How do I set an alias to a terminal line?How do I create a permanent Bash alias?How do I create a permanent Bash alias?Differences between fish and bash to pass commandline arguments to alias functions?How to add an alias to a command in terminal?alias of nodejs as node on 14.04add alias to rootHow can I run original command that aliased with same name?How would I create an alias to run a game? (Minecraft)Bash al (alias local) function not foundWhat is the correct way to create alias to snap package in Ubuntu 16.04?How to set an Alias in bashrc so that System IP can be found using a simple alias command?

How to avoid voltage drop when using full bridge rectifier as reverse polarity protection

Why did pressing the joystick button spit out keypresses?

What was the Shuttle Carrier Aircraft escape tunnel?

Old sci-fi story: radiation mutated the animals, a boy loses a limb, but it's okay because "humans used to do great with only two arms"

What's currently blocking the construction of the wall between Mexico and the US?

Can someone suggest a path to study Mordell-Weil theorem for someone studying on their own?

Run specific apex tests during "sfdx force:source:deploy"

How do I professionally let my manager know I'll quit over smoking in the office?

If I wouldn't want to read the story, is writing it still a good idea?

Why do some professors with PhDs leave their professorships to teach high school?

How many people are necessary to maintain modern civilisation?

How to remove this component from PCB

Should I prioritize my 401k over my student loans?

What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?

Trainee keeps missing deadlines for independent learning

What does "play with your toy’s toys" mean?

How to make clear to people I don't want to answer their "Where are you from?" question?

Does this Wild Magic result affect the sorcerer or just other creatures?

Can there be an UN resolution to remove a country from the UNSC?

Is it illegal to withhold someone's passport and green card in California?

.NET executes a SQL query and Active Monitor shows multiple rows blocking each other

Explain why a line can never intersect a plane in exactly two points.

Interaction between Leyline of Anticipation and Teferi, Time Raveler

What happens to Cessna electric flaps that are moving when power is lost?



How do I set an alias to a terminal line?


How do I create a permanent Bash alias?How do I create a permanent Bash alias?Differences between fish and bash to pass commandline arguments to alias functions?How to add an alias to a command in terminal?alias of nodejs as node on 14.04add alias to rootHow can I run original command that aliased with same name?How would I create an alias to run a game? (Minecraft)Bash al (alias local) function not foundWhat is the correct way to create alias to snap package in Ubuntu 16.04?How to set an Alias in bashrc so that System IP can be found using a simple alias command?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I want to easily set an alias git-go to this terminal line:



git commit -m "init "; git push; git status


So when I enter git-go this line should enter.



How can I do that? The answers I seen only cover alias of a command without parameters. But I want to set an alias to an arbitrary terminal line.










share|improve this question
























  • What did you try? Which other questions did you read? askubuntu.com/q/17536/507051 explains it quite good, what exactly is your question?

    – dessert
    9 hours ago












  • My issue was using double quotes instead of single for the outside quotes.

    – Philip Rego
    8 hours ago











  • You could as well do it the other way around using double quotes on the outside and single quotes on the inside.

    – Videonauth
    8 hours ago











  • @PhilipRego Even though you've accepted my answer (which shows a correct quoting syntax, as does Videonauth's answer), you may want to post your own answer that focuses specifically on quoting and shows why the way you'd been attempting to quote it didn't work. You're under no obligation to do so, of course. If you do, you may find this section of the Bash reference manual and this page helpful.

    – Eliah Kagan
    8 hours ago

















2















I want to easily set an alias git-go to this terminal line:



git commit -m "init "; git push; git status


So when I enter git-go this line should enter.



How can I do that? The answers I seen only cover alias of a command without parameters. But I want to set an alias to an arbitrary terminal line.










share|improve this question
























  • What did you try? Which other questions did you read? askubuntu.com/q/17536/507051 explains it quite good, what exactly is your question?

    – dessert
    9 hours ago












  • My issue was using double quotes instead of single for the outside quotes.

    – Philip Rego
    8 hours ago











  • You could as well do it the other way around using double quotes on the outside and single quotes on the inside.

    – Videonauth
    8 hours ago











  • @PhilipRego Even though you've accepted my answer (which shows a correct quoting syntax, as does Videonauth's answer), you may want to post your own answer that focuses specifically on quoting and shows why the way you'd been attempting to quote it didn't work. You're under no obligation to do so, of course. If you do, you may find this section of the Bash reference manual and this page helpful.

    – Eliah Kagan
    8 hours ago













2












2








2


0






I want to easily set an alias git-go to this terminal line:



git commit -m "init "; git push; git status


So when I enter git-go this line should enter.



How can I do that? The answers I seen only cover alias of a command without parameters. But I want to set an alias to an arbitrary terminal line.










share|improve this question
















I want to easily set an alias git-go to this terminal line:



git commit -m "init "; git push; git status


So when I enter git-go this line should enter.



How can I do that? The answers I seen only cover alias of a command without parameters. But I want to set an alias to an arbitrary terminal line.







command-line bash alias






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









Eliah Kagan

84.9k22236377




84.9k22236377










asked 9 hours ago









Philip RegoPhilip Rego

357




357












  • What did you try? Which other questions did you read? askubuntu.com/q/17536/507051 explains it quite good, what exactly is your question?

    – dessert
    9 hours ago












  • My issue was using double quotes instead of single for the outside quotes.

    – Philip Rego
    8 hours ago











  • You could as well do it the other way around using double quotes on the outside and single quotes on the inside.

    – Videonauth
    8 hours ago











  • @PhilipRego Even though you've accepted my answer (which shows a correct quoting syntax, as does Videonauth's answer), you may want to post your own answer that focuses specifically on quoting and shows why the way you'd been attempting to quote it didn't work. You're under no obligation to do so, of course. If you do, you may find this section of the Bash reference manual and this page helpful.

    – Eliah Kagan
    8 hours ago

















  • What did you try? Which other questions did you read? askubuntu.com/q/17536/507051 explains it quite good, what exactly is your question?

    – dessert
    9 hours ago












  • My issue was using double quotes instead of single for the outside quotes.

    – Philip Rego
    8 hours ago











  • You could as well do it the other way around using double quotes on the outside and single quotes on the inside.

    – Videonauth
    8 hours ago











  • @PhilipRego Even though you've accepted my answer (which shows a correct quoting syntax, as does Videonauth's answer), you may want to post your own answer that focuses specifically on quoting and shows why the way you'd been attempting to quote it didn't work. You're under no obligation to do so, of course. If you do, you may find this section of the Bash reference manual and this page helpful.

    – Eliah Kagan
    8 hours ago
















What did you try? Which other questions did you read? askubuntu.com/q/17536/507051 explains it quite good, what exactly is your question?

– dessert
9 hours ago






What did you try? Which other questions did you read? askubuntu.com/q/17536/507051 explains it quite good, what exactly is your question?

– dessert
9 hours ago














My issue was using double quotes instead of single for the outside quotes.

– Philip Rego
8 hours ago





My issue was using double quotes instead of single for the outside quotes.

– Philip Rego
8 hours ago













You could as well do it the other way around using double quotes on the outside and single quotes on the inside.

– Videonauth
8 hours ago





You could as well do it the other way around using double quotes on the outside and single quotes on the inside.

– Videonauth
8 hours ago













@PhilipRego Even though you've accepted my answer (which shows a correct quoting syntax, as does Videonauth's answer), you may want to post your own answer that focuses specifically on quoting and shows why the way you'd been attempting to quote it didn't work. You're under no obligation to do so, of course. If you do, you may find this section of the Bash reference manual and this page helpful.

– Eliah Kagan
8 hours ago





@PhilipRego Even though you've accepted my answer (which shows a correct quoting syntax, as does Videonauth's answer), you may want to post your own answer that focuses specifically on quoting and shows why the way you'd been attempting to quote it didn't work. You're under no obligation to do so, of course. If you do, you may find this section of the Bash reference manual and this page helpful.

– Eliah Kagan
8 hours ago










2 Answers
2






active

oldest

votes


















3














You do this the same way you would set any alias.





alias git-go='git commit -m "init "; git push; git status'


The situation where it gets tricky is not when an alias runs a command and passes arguments to that command, nor even when an alias runs multiple commands separated by ;, but instead is when you want an alias to accept and use its own command-line arguments.



For example, anything you write after the name of that alias will be pasted onto the end, and thus passed as command-line arguments to the third git command, after git status. (Really it's not so much that the following text is pasted onto the end, as much as it is that the following text is left alone and the alias name is replaced with its definition.)



So you can run your alias without arguments, which works, and the last command is git status:



git-go


Or you can run it with arguments that you want passed to git status. For example, when you run it this way, the last command is git-status --show-stash:



git-go --show-stash


What you cannot do with an alias in Bash (and other Bourne-style shells) is to make the alias accept command-line arguments and place them elsewhere than the end.



For example, suppose you wanted git-go to accept an argument that it uses for the commit message. You would not be able to write this as an alias. The solution would be to write it as a shell function instead:



git-go() git commit -m "$1"; git push; git status; 


In the definition of a shell function, the positional parameters $1, $2, and so forth hold the values of the command-line arguments passed to the shell function. Aliases have no functionality that corresponds to this, because alias expansion is really a form of macro processing, taking place very early, when the shell parses a command.



You can, of course, write it as a shell function even if you don't need to use positional parameters in the definition, as Videonauth suggests.






share|improve this answer






























    3














    You can declare it a function in your ~/.bash_aliases file like so:



    git-go()
    git commit -m "init "
    git push
    git status



    or you can create an alias in the same file like so:



    alias git-go='git commit -m "init "; git push; git status'


    Do not forget to reopen your terminal or source the file (. ~/.bash_aliases) after you changed it.






    share|improve this answer

























    • One benefit of writing a shell function instead of an alias is that one needn't nest quotes. This answer thus addresses the central problem the OP turned out to be having more directly than mine does.

      – Eliah Kagan
      8 hours ago












    • @EliahKagan Both are fine for that question although yours is more throughout. Nice to see you back.

      – Videonauth
      8 hours ago













    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1152381%2fhow-do-i-set-an-alias-to-a-terminal-line%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    You do this the same way you would set any alias.





    alias git-go='git commit -m "init "; git push; git status'


    The situation where it gets tricky is not when an alias runs a command and passes arguments to that command, nor even when an alias runs multiple commands separated by ;, but instead is when you want an alias to accept and use its own command-line arguments.



    For example, anything you write after the name of that alias will be pasted onto the end, and thus passed as command-line arguments to the third git command, after git status. (Really it's not so much that the following text is pasted onto the end, as much as it is that the following text is left alone and the alias name is replaced with its definition.)



    So you can run your alias without arguments, which works, and the last command is git status:



    git-go


    Or you can run it with arguments that you want passed to git status. For example, when you run it this way, the last command is git-status --show-stash:



    git-go --show-stash


    What you cannot do with an alias in Bash (and other Bourne-style shells) is to make the alias accept command-line arguments and place them elsewhere than the end.



    For example, suppose you wanted git-go to accept an argument that it uses for the commit message. You would not be able to write this as an alias. The solution would be to write it as a shell function instead:



    git-go() git commit -m "$1"; git push; git status; 


    In the definition of a shell function, the positional parameters $1, $2, and so forth hold the values of the command-line arguments passed to the shell function. Aliases have no functionality that corresponds to this, because alias expansion is really a form of macro processing, taking place very early, when the shell parses a command.



    You can, of course, write it as a shell function even if you don't need to use positional parameters in the definition, as Videonauth suggests.






    share|improve this answer



























      3














      You do this the same way you would set any alias.





      alias git-go='git commit -m "init "; git push; git status'


      The situation where it gets tricky is not when an alias runs a command and passes arguments to that command, nor even when an alias runs multiple commands separated by ;, but instead is when you want an alias to accept and use its own command-line arguments.



      For example, anything you write after the name of that alias will be pasted onto the end, and thus passed as command-line arguments to the third git command, after git status. (Really it's not so much that the following text is pasted onto the end, as much as it is that the following text is left alone and the alias name is replaced with its definition.)



      So you can run your alias without arguments, which works, and the last command is git status:



      git-go


      Or you can run it with arguments that you want passed to git status. For example, when you run it this way, the last command is git-status --show-stash:



      git-go --show-stash


      What you cannot do with an alias in Bash (and other Bourne-style shells) is to make the alias accept command-line arguments and place them elsewhere than the end.



      For example, suppose you wanted git-go to accept an argument that it uses for the commit message. You would not be able to write this as an alias. The solution would be to write it as a shell function instead:



      git-go() git commit -m "$1"; git push; git status; 


      In the definition of a shell function, the positional parameters $1, $2, and so forth hold the values of the command-line arguments passed to the shell function. Aliases have no functionality that corresponds to this, because alias expansion is really a form of macro processing, taking place very early, when the shell parses a command.



      You can, of course, write it as a shell function even if you don't need to use positional parameters in the definition, as Videonauth suggests.






      share|improve this answer

























        3












        3








        3







        You do this the same way you would set any alias.





        alias git-go='git commit -m "init "; git push; git status'


        The situation where it gets tricky is not when an alias runs a command and passes arguments to that command, nor even when an alias runs multiple commands separated by ;, but instead is when you want an alias to accept and use its own command-line arguments.



        For example, anything you write after the name of that alias will be pasted onto the end, and thus passed as command-line arguments to the third git command, after git status. (Really it's not so much that the following text is pasted onto the end, as much as it is that the following text is left alone and the alias name is replaced with its definition.)



        So you can run your alias without arguments, which works, and the last command is git status:



        git-go


        Or you can run it with arguments that you want passed to git status. For example, when you run it this way, the last command is git-status --show-stash:



        git-go --show-stash


        What you cannot do with an alias in Bash (and other Bourne-style shells) is to make the alias accept command-line arguments and place them elsewhere than the end.



        For example, suppose you wanted git-go to accept an argument that it uses for the commit message. You would not be able to write this as an alias. The solution would be to write it as a shell function instead:



        git-go() git commit -m "$1"; git push; git status; 


        In the definition of a shell function, the positional parameters $1, $2, and so forth hold the values of the command-line arguments passed to the shell function. Aliases have no functionality that corresponds to this, because alias expansion is really a form of macro processing, taking place very early, when the shell parses a command.



        You can, of course, write it as a shell function even if you don't need to use positional parameters in the definition, as Videonauth suggests.






        share|improve this answer













        You do this the same way you would set any alias.





        alias git-go='git commit -m "init "; git push; git status'


        The situation where it gets tricky is not when an alias runs a command and passes arguments to that command, nor even when an alias runs multiple commands separated by ;, but instead is when you want an alias to accept and use its own command-line arguments.



        For example, anything you write after the name of that alias will be pasted onto the end, and thus passed as command-line arguments to the third git command, after git status. (Really it's not so much that the following text is pasted onto the end, as much as it is that the following text is left alone and the alias name is replaced with its definition.)



        So you can run your alias without arguments, which works, and the last command is git status:



        git-go


        Or you can run it with arguments that you want passed to git status. For example, when you run it this way, the last command is git-status --show-stash:



        git-go --show-stash


        What you cannot do with an alias in Bash (and other Bourne-style shells) is to make the alias accept command-line arguments and place them elsewhere than the end.



        For example, suppose you wanted git-go to accept an argument that it uses for the commit message. You would not be able to write this as an alias. The solution would be to write it as a shell function instead:



        git-go() git commit -m "$1"; git push; git status; 


        In the definition of a shell function, the positional parameters $1, $2, and so forth hold the values of the command-line arguments passed to the shell function. Aliases have no functionality that corresponds to this, because alias expansion is really a form of macro processing, taking place very early, when the shell parses a command.



        You can, of course, write it as a shell function even if you don't need to use positional parameters in the definition, as Videonauth suggests.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 9 hours ago









        Eliah KaganEliah Kagan

        84.9k22236377




        84.9k22236377























            3














            You can declare it a function in your ~/.bash_aliases file like so:



            git-go()
            git commit -m "init "
            git push
            git status



            or you can create an alias in the same file like so:



            alias git-go='git commit -m "init "; git push; git status'


            Do not forget to reopen your terminal or source the file (. ~/.bash_aliases) after you changed it.






            share|improve this answer

























            • One benefit of writing a shell function instead of an alias is that one needn't nest quotes. This answer thus addresses the central problem the OP turned out to be having more directly than mine does.

              – Eliah Kagan
              8 hours ago












            • @EliahKagan Both are fine for that question although yours is more throughout. Nice to see you back.

              – Videonauth
              8 hours ago















            3














            You can declare it a function in your ~/.bash_aliases file like so:



            git-go()
            git commit -m "init "
            git push
            git status



            or you can create an alias in the same file like so:



            alias git-go='git commit -m "init "; git push; git status'


            Do not forget to reopen your terminal or source the file (. ~/.bash_aliases) after you changed it.






            share|improve this answer

























            • One benefit of writing a shell function instead of an alias is that one needn't nest quotes. This answer thus addresses the central problem the OP turned out to be having more directly than mine does.

              – Eliah Kagan
              8 hours ago












            • @EliahKagan Both are fine for that question although yours is more throughout. Nice to see you back.

              – Videonauth
              8 hours ago













            3












            3








            3







            You can declare it a function in your ~/.bash_aliases file like so:



            git-go()
            git commit -m "init "
            git push
            git status



            or you can create an alias in the same file like so:



            alias git-go='git commit -m "init "; git push; git status'


            Do not forget to reopen your terminal or source the file (. ~/.bash_aliases) after you changed it.






            share|improve this answer















            You can declare it a function in your ~/.bash_aliases file like so:



            git-go()
            git commit -m "init "
            git push
            git status



            or you can create an alias in the same file like so:



            alias git-go='git commit -m "init "; git push; git status'


            Do not forget to reopen your terminal or source the file (. ~/.bash_aliases) after you changed it.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 8 hours ago

























            answered 9 hours ago









            VideonauthVideonauth

            25.9k1281105




            25.9k1281105












            • One benefit of writing a shell function instead of an alias is that one needn't nest quotes. This answer thus addresses the central problem the OP turned out to be having more directly than mine does.

              – Eliah Kagan
              8 hours ago












            • @EliahKagan Both are fine for that question although yours is more throughout. Nice to see you back.

              – Videonauth
              8 hours ago

















            • One benefit of writing a shell function instead of an alias is that one needn't nest quotes. This answer thus addresses the central problem the OP turned out to be having more directly than mine does.

              – Eliah Kagan
              8 hours ago












            • @EliahKagan Both are fine for that question although yours is more throughout. Nice to see you back.

              – Videonauth
              8 hours ago
















            One benefit of writing a shell function instead of an alias is that one needn't nest quotes. This answer thus addresses the central problem the OP turned out to be having more directly than mine does.

            – Eliah Kagan
            8 hours ago






            One benefit of writing a shell function instead of an alias is that one needn't nest quotes. This answer thus addresses the central problem the OP turned out to be having more directly than mine does.

            – Eliah Kagan
            8 hours ago














            @EliahKagan Both are fine for that question although yours is more throughout. Nice to see you back.

            – Videonauth
            8 hours ago





            @EliahKagan Both are fine for that question although yours is more throughout. Nice to see you back.

            – Videonauth
            8 hours ago

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1152381%2fhow-do-i-set-an-alias-to-a-terminal-line%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її