Create âfunctionâ to run bash?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have the following bash:
cd /aPath/
for x in y.*.gz
> do something $file.dd.mm.yyyy >> /anotherPath/aFile
> done
I would like to pass in an argument to this file which will represent the month to insert in to 'mm'. So I would like to be able to call from the command line:
myFunc 08
and it would run:
cd /aPath/
for x in y.*.gz
> do something $file.dd.08.yyyy >> /anotherPath/aFile
> done
How do I do this/can I define something in my bash_profile ?
bash
add a comment |Â
up vote
1
down vote
favorite
I have the following bash:
cd /aPath/
for x in y.*.gz
> do something $file.dd.mm.yyyy >> /anotherPath/aFile
> done
I would like to pass in an argument to this file which will represent the month to insert in to 'mm'. So I would like to be able to call from the command line:
myFunc 08
and it would run:
cd /aPath/
for x in y.*.gz
> do something $file.dd.08.yyyy >> /anotherPath/aFile
> done
How do I do this/can I define something in my bash_profile ?
bash
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have the following bash:
cd /aPath/
for x in y.*.gz
> do something $file.dd.mm.yyyy >> /anotherPath/aFile
> done
I would like to pass in an argument to this file which will represent the month to insert in to 'mm'. So I would like to be able to call from the command line:
myFunc 08
and it would run:
cd /aPath/
for x in y.*.gz
> do something $file.dd.08.yyyy >> /anotherPath/aFile
> done
How do I do this/can I define something in my bash_profile ?
bash
I have the following bash:
cd /aPath/
for x in y.*.gz
> do something $file.dd.mm.yyyy >> /anotherPath/aFile
> done
I would like to pass in an argument to this file which will represent the month to insert in to 'mm'. So I would like to be able to call from the command line:
myFunc 08
and it would run:
cd /aPath/
for x in y.*.gz
> do something $file.dd.08.yyyy >> /anotherPath/aFile
> done
How do I do this/can I define something in my bash_profile ?
bash
bash
asked Sep 25 '17 at 8:04
user997112
2974619
2974619
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
I would add the function into my /home/user/.bashrc
in example
myFunc()
mm=$1
FILES=/home/user/*
for f in $FILES; do
if [[ $f == filename.dd.$mm.yyyy ]]; then
ls -la $f
fi
done
and remembering to reload .bashrc file with the command source ~/.bashrc
, I would call the function from the shell.
mm=$1
will get the first parameter(argument) you passed to the function by calling myFunc 08
and put it into $mm
variable (which is pretty useless step, you can directly use $1
variable wherever you need into the function)
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
I would add the function into my /home/user/.bashrc
in example
myFunc()
mm=$1
FILES=/home/user/*
for f in $FILES; do
if [[ $f == filename.dd.$mm.yyyy ]]; then
ls -la $f
fi
done
and remembering to reload .bashrc file with the command source ~/.bashrc
, I would call the function from the shell.
mm=$1
will get the first parameter(argument) you passed to the function by calling myFunc 08
and put it into $mm
variable (which is pretty useless step, you can directly use $1
variable wherever you need into the function)
add a comment |Â
up vote
2
down vote
accepted
I would add the function into my /home/user/.bashrc
in example
myFunc()
mm=$1
FILES=/home/user/*
for f in $FILES; do
if [[ $f == filename.dd.$mm.yyyy ]]; then
ls -la $f
fi
done
and remembering to reload .bashrc file with the command source ~/.bashrc
, I would call the function from the shell.
mm=$1
will get the first parameter(argument) you passed to the function by calling myFunc 08
and put it into $mm
variable (which is pretty useless step, you can directly use $1
variable wherever you need into the function)
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
I would add the function into my /home/user/.bashrc
in example
myFunc()
mm=$1
FILES=/home/user/*
for f in $FILES; do
if [[ $f == filename.dd.$mm.yyyy ]]; then
ls -la $f
fi
done
and remembering to reload .bashrc file with the command source ~/.bashrc
, I would call the function from the shell.
mm=$1
will get the first parameter(argument) you passed to the function by calling myFunc 08
and put it into $mm
variable (which is pretty useless step, you can directly use $1
variable wherever you need into the function)
I would add the function into my /home/user/.bashrc
in example
myFunc()
mm=$1
FILES=/home/user/*
for f in $FILES; do
if [[ $f == filename.dd.$mm.yyyy ]]; then
ls -la $f
fi
done
and remembering to reload .bashrc file with the command source ~/.bashrc
, I would call the function from the shell.
mm=$1
will get the first parameter(argument) you passed to the function by calling myFunc 08
and put it into $mm
variable (which is pretty useless step, you can directly use $1
variable wherever you need into the function)
edited Sep 25 '17 at 8:50
answered Sep 25 '17 at 8:22
lese
2,11021227
2,11021227
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394265%2fcreate-function-to-run-bash%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password