Creating a bash alias that ends in single quotation





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a command line string:



ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '


which outputs file names in the current folder, in a single line, surrounded by quotations.



I attempted to add this to my .bash_profile as an alias, however I think the single quotes are causing an issue and I can't get it to work.



I tried this with no luck:



alias='ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' ''


How would one go about creating an alias for the above?



Thanks in advance to anyone who can help with this noob question and I appreciate your time :)



Cheers,



Stephen.










share|improve this question































    0















    I have a command line string:



    ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '


    which outputs file names in the current folder, in a single line, surrounded by quotations.



    I attempted to add this to my .bash_profile as an alias, however I think the single quotes are causing an issue and I can't get it to work.



    I tried this with no luck:



    alias='ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' ''


    How would one go about creating an alias for the above?



    Thanks in advance to anyone who can help with this noob question and I appreciate your time :)



    Cheers,



    Stephen.










    share|improve this question



























      0












      0








      0








      I have a command line string:



      ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '


      which outputs file names in the current folder, in a single line, surrounded by quotations.



      I attempted to add this to my .bash_profile as an alias, however I think the single quotes are causing an issue and I can't get it to work.



      I tried this with no luck:



      alias='ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' ''


      How would one go about creating an alias for the above?



      Thanks in advance to anyone who can help with this noob question and I appreciate your time :)



      Cheers,



      Stephen.










      share|improve this question
















      I have a command line string:



      ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '


      which outputs file names in the current folder, in a single line, surrounded by quotations.



      I attempted to add this to my .bash_profile as an alias, however I think the single quotes are causing an issue and I can't get it to work.



      I tried this with no luck:



      alias='ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' ''


      How would one go about creating an alias for the above?



      Thanks in advance to anyone who can help with this noob question and I appreciate your time :)



      Cheers,



      Stephen.







      bash command-line-interface alias






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 13:21







      Stephen J Pereira

















      asked Nov 22 '18 at 13:17









      Stephen J PereiraStephen J Pereira

      62




      62
























          3 Answers
          3






          active

          oldest

          votes


















          0














          work here with using "



          alias X="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"





          share|improve this answer



















          • 1





            Thank you so much :) that worked perfectly!

            – Stephen J Pereira
            Nov 22 '18 at 13:23











          • @StephenJPereira If you problem was resolved, you should accept an answer to close the question.

            – Socowi
            Nov 23 '18 at 16:57



















          2














          Enquote the whole command in double quotes and escape the double quotes inside the command with a backslash:



          alias a="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"


          or use a function



          a() {
          ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '
          }


          By the way: Parsing ls is a bad practice. It would be safer and easier to use globs and printf:



          printf '"%s" ' *


          or, if you want to properly quote for using the arguments inside eval or something similar



          printf '%q ' *





          share|improve this answer































            0














            The alias should enclose the command line into ' AND each already existing ' should be escaped with '''



            Give a try to this:



            alias lsquoted='ls | sed -e '''s/^/"/g''' -e '''s/$/"/g''' | tr '''n''' ''' ''''





            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              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%2fstackoverflow.com%2fquestions%2f53431883%2fcreating-a-bash-alias-that-ends-in-single-quotation%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              work here with using "



              alias X="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"





              share|improve this answer



















              • 1





                Thank you so much :) that worked perfectly!

                – Stephen J Pereira
                Nov 22 '18 at 13:23











              • @StephenJPereira If you problem was resolved, you should accept an answer to close the question.

                – Socowi
                Nov 23 '18 at 16:57
















              0














              work here with using "



              alias X="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"





              share|improve this answer



















              • 1





                Thank you so much :) that worked perfectly!

                – Stephen J Pereira
                Nov 22 '18 at 13:23











              • @StephenJPereira If you problem was resolved, you should accept an answer to close the question.

                – Socowi
                Nov 23 '18 at 16:57














              0












              0








              0







              work here with using "



              alias X="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"





              share|improve this answer













              work here with using "



              alias X="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 22 '18 at 13:21









              Incrivel Monstro VerdeIncrivel Monstro Verde

              43316




              43316








              • 1





                Thank you so much :) that worked perfectly!

                – Stephen J Pereira
                Nov 22 '18 at 13:23











              • @StephenJPereira If you problem was resolved, you should accept an answer to close the question.

                – Socowi
                Nov 23 '18 at 16:57














              • 1





                Thank you so much :) that worked perfectly!

                – Stephen J Pereira
                Nov 22 '18 at 13:23











              • @StephenJPereira If you problem was resolved, you should accept an answer to close the question.

                – Socowi
                Nov 23 '18 at 16:57








              1




              1





              Thank you so much :) that worked perfectly!

              – Stephen J Pereira
              Nov 22 '18 at 13:23





              Thank you so much :) that worked perfectly!

              – Stephen J Pereira
              Nov 22 '18 at 13:23













              @StephenJPereira If you problem was resolved, you should accept an answer to close the question.

              – Socowi
              Nov 23 '18 at 16:57





              @StephenJPereira If you problem was resolved, you should accept an answer to close the question.

              – Socowi
              Nov 23 '18 at 16:57













              2














              Enquote the whole command in double quotes and escape the double quotes inside the command with a backslash:



              alias a="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"


              or use a function



              a() {
              ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '
              }


              By the way: Parsing ls is a bad practice. It would be safer and easier to use globs and printf:



              printf '"%s" ' *


              or, if you want to properly quote for using the arguments inside eval or something similar



              printf '%q ' *





              share|improve this answer




























                2














                Enquote the whole command in double quotes and escape the double quotes inside the command with a backslash:



                alias a="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"


                or use a function



                a() {
                ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '
                }


                By the way: Parsing ls is a bad practice. It would be safer and easier to use globs and printf:



                printf '"%s" ' *


                or, if you want to properly quote for using the arguments inside eval or something similar



                printf '%q ' *





                share|improve this answer


























                  2












                  2








                  2







                  Enquote the whole command in double quotes and escape the double quotes inside the command with a backslash:



                  alias a="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"


                  or use a function



                  a() {
                  ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '
                  }


                  By the way: Parsing ls is a bad practice. It would be safer and easier to use globs and printf:



                  printf '"%s" ' *


                  or, if you want to properly quote for using the arguments inside eval or something similar



                  printf '%q ' *





                  share|improve this answer













                  Enquote the whole command in double quotes and escape the double quotes inside the command with a backslash:



                  alias a="ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '"


                  or use a function



                  a() {
                  ls | sed -e 's/^/"/g' -e 's/$/"/g' | tr 'n' ' '
                  }


                  By the way: Parsing ls is a bad practice. It would be safer and easier to use globs and printf:



                  printf '"%s" ' *


                  or, if you want to properly quote for using the arguments inside eval or something similar



                  printf '%q ' *






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 13:21









                  SocowiSocowi

                  7,93921428




                  7,93921428























                      0














                      The alias should enclose the command line into ' AND each already existing ' should be escaped with '''



                      Give a try to this:



                      alias lsquoted='ls | sed -e '''s/^/"/g''' -e '''s/$/"/g''' | tr '''n''' ''' ''''





                      share|improve this answer




























                        0














                        The alias should enclose the command line into ' AND each already existing ' should be escaped with '''



                        Give a try to this:



                        alias lsquoted='ls | sed -e '''s/^/"/g''' -e '''s/$/"/g''' | tr '''n''' ''' ''''





                        share|improve this answer


























                          0












                          0








                          0







                          The alias should enclose the command line into ' AND each already existing ' should be escaped with '''



                          Give a try to this:



                          alias lsquoted='ls | sed -e '''s/^/"/g''' -e '''s/$/"/g''' | tr '''n''' ''' ''''





                          share|improve this answer













                          The alias should enclose the command line into ' AND each already existing ' should be escaped with '''



                          Give a try to this:



                          alias lsquoted='ls | sed -e '''s/^/"/g''' -e '''s/$/"/g''' | tr '''n''' ''' ''''






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 22 '18 at 13:23









                          Jay jargotJay jargot

                          1,9621511




                          1,9621511






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • 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%2fstackoverflow.com%2fquestions%2f53431883%2fcreating-a-bash-alias-that-ends-in-single-quotation%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

                              How to pass form data using jquery Ajax to insert data in database?

                              National Museum of Racing and Hall of Fame

                              Guess what letter conforming each word