How to ignore keys pushd

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a bash script in which it is necessary to specify keys and parameters. I created a command for it using alias.
alias command="pushd /path; ./somescript.sh; popd"
After the script does the work, I need to return to the directory from which the script was called.
But I get an error:
bash: popd: -o: invalid number
popd: using: popd [-n] [+N | -N]
Language of my sistem is not English, I'm sorry if in the original it looks differently.
What I should to do?
bash shell-script bashrc
add a comment |Â
up vote
0
down vote
favorite
I have a bash script in which it is necessary to specify keys and parameters. I created a command for it using alias.
alias command="pushd /path; ./somescript.sh; popd"
After the script does the work, I need to return to the directory from which the script was called.
But I get an error:
bash: popd: -o: invalid number
popd: using: popd [-n] [+N | -N]
Language of my sistem is not English, I'm sorry if in the original it looks differently.
What I should to do?
bash shell-script bashrc
are you running that withcommand -oor such?
â ilkkachu
Dec 25 '17 at 17:37
1
"I need to return to the directory from which the script was called". The script will not change your current directory in the interactive session.
â jimmij
Dec 25 '17 at 17:41
Rather thanpushdandpopd, justcdin a subshell:(cd /path; ./somescript). That won't help if you callcommand -o(for that, see ilkkachu's example of a function)
â Fox
Dec 25 '17 at 18:49
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a bash script in which it is necessary to specify keys and parameters. I created a command for it using alias.
alias command="pushd /path; ./somescript.sh; popd"
After the script does the work, I need to return to the directory from which the script was called.
But I get an error:
bash: popd: -o: invalid number
popd: using: popd [-n] [+N | -N]
Language of my sistem is not English, I'm sorry if in the original it looks differently.
What I should to do?
bash shell-script bashrc
I have a bash script in which it is necessary to specify keys and parameters. I created a command for it using alias.
alias command="pushd /path; ./somescript.sh; popd"
After the script does the work, I need to return to the directory from which the script was called.
But I get an error:
bash: popd: -o: invalid number
popd: using: popd [-n] [+N | -N]
Language of my sistem is not English, I'm sorry if in the original it looks differently.
What I should to do?
bash shell-script bashrc
asked Dec 25 '17 at 17:21
MurelloS
11
11
are you running that withcommand -oor such?
â ilkkachu
Dec 25 '17 at 17:37
1
"I need to return to the directory from which the script was called". The script will not change your current directory in the interactive session.
â jimmij
Dec 25 '17 at 17:41
Rather thanpushdandpopd, justcdin a subshell:(cd /path; ./somescript). That won't help if you callcommand -o(for that, see ilkkachu's example of a function)
â Fox
Dec 25 '17 at 18:49
add a comment |Â
are you running that withcommand -oor such?
â ilkkachu
Dec 25 '17 at 17:37
1
"I need to return to the directory from which the script was called". The script will not change your current directory in the interactive session.
â jimmij
Dec 25 '17 at 17:41
Rather thanpushdandpopd, justcdin a subshell:(cd /path; ./somescript). That won't help if you callcommand -o(for that, see ilkkachu's example of a function)
â Fox
Dec 25 '17 at 18:49
are you running that with
command -o or such?â ilkkachu
Dec 25 '17 at 17:37
are you running that with
command -o or such?â ilkkachu
Dec 25 '17 at 17:37
1
1
"I need to return to the directory from which the script was called". The script will not change your current directory in the interactive session.
â jimmij
Dec 25 '17 at 17:41
"I need to return to the directory from which the script was called". The script will not change your current directory in the interactive session.
â jimmij
Dec 25 '17 at 17:41
Rather than
pushd and popd, just cd in a subshell: (cd /path; ./somescript). That won't help if you call command -o (for that, see ilkkachu's example of a function)â Fox
Dec 25 '17 at 18:49
Rather than
pushd and popd, just cd in a subshell: (cd /path; ./somescript). That won't help if you call command -o (for that, see ilkkachu's example of a function)â Fox
Dec 25 '17 at 18:49
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
This works fine:
$ alias foo="pushd /; ls -ld ./tmp; popd"
$ foo
/ ~
drwxrwxrwt 12 root root 4096 Dec 25 19:30 ./tmp/
~
But if you need to pass parameters to the middle command of the alias, you'll need to use a function instead. Otherwise the parameters are just added to the end of the alias, so they go as parameters to popd.
Do this instead:
something()
pushd /path > /dev/null
./somescript.sh "$@"
popd > /dev/null
something -o blahblah
Using command as the name of the alias/function might not be the best call, it's a shell builtin that's used to call external commands, skipping functions with the same name.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This works fine:
$ alias foo="pushd /; ls -ld ./tmp; popd"
$ foo
/ ~
drwxrwxrwt 12 root root 4096 Dec 25 19:30 ./tmp/
~
But if you need to pass parameters to the middle command of the alias, you'll need to use a function instead. Otherwise the parameters are just added to the end of the alias, so they go as parameters to popd.
Do this instead:
something()
pushd /path > /dev/null
./somescript.sh "$@"
popd > /dev/null
something -o blahblah
Using command as the name of the alias/function might not be the best call, it's a shell builtin that's used to call external commands, skipping functions with the same name.
add a comment |Â
up vote
0
down vote
This works fine:
$ alias foo="pushd /; ls -ld ./tmp; popd"
$ foo
/ ~
drwxrwxrwt 12 root root 4096 Dec 25 19:30 ./tmp/
~
But if you need to pass parameters to the middle command of the alias, you'll need to use a function instead. Otherwise the parameters are just added to the end of the alias, so they go as parameters to popd.
Do this instead:
something()
pushd /path > /dev/null
./somescript.sh "$@"
popd > /dev/null
something -o blahblah
Using command as the name of the alias/function might not be the best call, it's a shell builtin that's used to call external commands, skipping functions with the same name.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This works fine:
$ alias foo="pushd /; ls -ld ./tmp; popd"
$ foo
/ ~
drwxrwxrwt 12 root root 4096 Dec 25 19:30 ./tmp/
~
But if you need to pass parameters to the middle command of the alias, you'll need to use a function instead. Otherwise the parameters are just added to the end of the alias, so they go as parameters to popd.
Do this instead:
something()
pushd /path > /dev/null
./somescript.sh "$@"
popd > /dev/null
something -o blahblah
Using command as the name of the alias/function might not be the best call, it's a shell builtin that's used to call external commands, skipping functions with the same name.
This works fine:
$ alias foo="pushd /; ls -ld ./tmp; popd"
$ foo
/ ~
drwxrwxrwt 12 root root 4096 Dec 25 19:30 ./tmp/
~
But if you need to pass parameters to the middle command of the alias, you'll need to use a function instead. Otherwise the parameters are just added to the end of the alias, so they go as parameters to popd.
Do this instead:
something()
pushd /path > /dev/null
./somescript.sh "$@"
popd > /dev/null
something -o blahblah
Using command as the name of the alias/function might not be the best call, it's a shell builtin that's used to call external commands, skipping functions with the same name.
answered Dec 25 '17 at 17:41
ilkkachu
49.9k674137
49.9k674137
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%2f412989%2fhow-to-ignore-keys-pushd%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
are you running that with
command -oor such?â ilkkachu
Dec 25 '17 at 17:37
1
"I need to return to the directory from which the script was called". The script will not change your current directory in the interactive session.
â jimmij
Dec 25 '17 at 17:41
Rather than
pushdandpopd, justcdin a subshell:(cd /path; ./somescript). That won't help if you callcommand -o(for that, see ilkkachu's example of a function)â Fox
Dec 25 '17 at 18:49