How to ignore keys pushd

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question




















  • are you running that with command -o or 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 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














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?







share|improve this question




















  • are you running that with command -o or 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 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












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?







share|improve this question












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?









share|improve this question











share|improve this question




share|improve this question










asked Dec 25 '17 at 17:21









MurelloS

11




11











  • are you running that with command -o or 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 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
















  • are you running that with command -o or 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 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















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










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.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    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






























    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.






    share|improve this answer
























      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.






      share|improve this answer






















        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 25 '17 at 17:41









        ilkkachu

        49.9k674137




        49.9k674137






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)