Construction an a command line bash script with spaces in path names [duplicate] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionWhy does my shell script choke on whitespace or other special characters?How can we run a command stored in a variable?Bash script with quotes and spacesBash : command line with optional argumentsMaking md5sum understand file names with spacesCannot create root jailDeleting files with spaces in their namesCron only occasionally sends e-mail on output and errorsBash root to user. Best in same or separate script?How does 'find -exec' pass file names with spaces?Spaces for variables in bash scriptIssues setting a variable to a string containing metacharacters, find, and another variable in csh

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Strange behaviour of Check

Windows 10: How to Lock (not sleep) laptop on lid close?

Complexity of many constant time steps with occasional logarithmic steps

Typsetting diagram chases (with TikZ?)

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Statistical model of ligand substitution

Is drag coefficient lowest at zero angle of attack?

Direct Experience of Meditation

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

How to market an anarchic city as a tourism spot to people living in civilized areas?

What can I do if my MacBook isn’t charging but already ran out?

Are my PIs rude or am I just being too sensitive?

Antler Helmet: Can it work?

Can smartphones with the same camera sensor have different image quality?

Why is "Captain Marvel" translated as male in Portugal?

Single author papers against my advisor's will?

Unable to start mainnet node docker container

What did Darwin mean by 'squib' here?

How do I keep my slimes from escaping their pens?

Jazz greats knew nothing of modes. Why are they used to improvise on standards?

Stars Make Stars

How to say 'striped' in Latin

Did the new image of black hole confirm the general theory of relativity?



Construction an a command line bash script with spaces in path names [duplicate]



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionWhy does my shell script choke on whitespace or other special characters?How can we run a command stored in a variable?Bash script with quotes and spacesBash : command line with optional argumentsMaking md5sum understand file names with spacesCannot create root jailDeleting files with spaces in their namesCron only occasionally sends e-mail on output and errorsBash root to user. Best in same or separate script?How does 'find -exec' pass file names with spaces?Spaces for variables in bash scriptIssues setting a variable to a string containing metacharacters, find, and another variable in csh



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








0
















This question already has an answer here:



  • Why does my shell script choke on whitespace or other special characters?

    4 answers



  • How can we run a command stored in a variable?

    3 answers



I need a simple script to call gcc but I've got a long list of libraries that I need to pass to it in a directory who's path has a space on it.



In place of gcc for testing my script I've used:



#!/bin/bash
for var in "$@"
do
echo "$var"
done


This is one of the umpteen attempts I've tried:



#!/bin/bash
LIBDIR="lib dir"
LIBS=
LIBS+="lib1 "
LIBS+="lib2 "
CMD="./debug.sh "
for LIB in $LIBS
do
CMD+="-I $LIBDIR/$LIB "
done
$CMD
exit


Obviously the problem is that bash cannot tell which spaces are meant to separate the arguments and which are not, but no matter how I place quotes or backslashes I cannot figure out how to 'quote' some of the spaces and not the others.










share|improve this question









New contributor




nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











marked as duplicate by Michael Homer, Sparhawk, muru, Mr Shunz, X Tian Apr 11 at 17:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























    0
















    This question already has an answer here:



    • Why does my shell script choke on whitespace or other special characters?

      4 answers



    • How can we run a command stored in a variable?

      3 answers



    I need a simple script to call gcc but I've got a long list of libraries that I need to pass to it in a directory who's path has a space on it.



    In place of gcc for testing my script I've used:



    #!/bin/bash
    for var in "$@"
    do
    echo "$var"
    done


    This is one of the umpteen attempts I've tried:



    #!/bin/bash
    LIBDIR="lib dir"
    LIBS=
    LIBS+="lib1 "
    LIBS+="lib2 "
    CMD="./debug.sh "
    for LIB in $LIBS
    do
    CMD+="-I $LIBDIR/$LIB "
    done
    $CMD
    exit


    Obviously the problem is that bash cannot tell which spaces are meant to separate the arguments and which are not, but no matter how I place quotes or backslashes I cannot figure out how to 'quote' some of the spaces and not the others.










    share|improve this question









    New contributor




    nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    marked as duplicate by Michael Homer, Sparhawk, muru, Mr Shunz, X Tian Apr 11 at 17:12


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















      0












      0








      0









      This question already has an answer here:



      • Why does my shell script choke on whitespace or other special characters?

        4 answers



      • How can we run a command stored in a variable?

        3 answers



      I need a simple script to call gcc but I've got a long list of libraries that I need to pass to it in a directory who's path has a space on it.



      In place of gcc for testing my script I've used:



      #!/bin/bash
      for var in "$@"
      do
      echo "$var"
      done


      This is one of the umpteen attempts I've tried:



      #!/bin/bash
      LIBDIR="lib dir"
      LIBS=
      LIBS+="lib1 "
      LIBS+="lib2 "
      CMD="./debug.sh "
      for LIB in $LIBS
      do
      CMD+="-I $LIBDIR/$LIB "
      done
      $CMD
      exit


      Obviously the problem is that bash cannot tell which spaces are meant to separate the arguments and which are not, but no matter how I place quotes or backslashes I cannot figure out how to 'quote' some of the spaces and not the others.










      share|improve this question









      New contributor




      nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.













      This question already has an answer here:



      • Why does my shell script choke on whitespace or other special characters?

        4 answers



      • How can we run a command stored in a variable?

        3 answers



      I need a simple script to call gcc but I've got a long list of libraries that I need to pass to it in a directory who's path has a space on it.



      In place of gcc for testing my script I've used:



      #!/bin/bash
      for var in "$@"
      do
      echo "$var"
      done


      This is one of the umpteen attempts I've tried:



      #!/bin/bash
      LIBDIR="lib dir"
      LIBS=
      LIBS+="lib1 "
      LIBS+="lib2 "
      CMD="./debug.sh "
      for LIB in $LIBS
      do
      CMD+="-I $LIBDIR/$LIB "
      done
      $CMD
      exit


      Obviously the problem is that bash cannot tell which spaces are meant to separate the arguments and which are not, but no matter how I place quotes or backslashes I cannot figure out how to 'quote' some of the spaces and not the others.





      This question already has an answer here:



      • Why does my shell script choke on whitespace or other special characters?

        4 answers



      • How can we run a command stored in a variable?

        3 answers







      bash quoting






      share|improve this question









      New contributor




      nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Apr 11 at 5:18









      Rui F Ribeiro

      42.1k1483142




      42.1k1483142






      New contributor




      nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Apr 11 at 4:37









      nyholkunyholku

      1




      1




      New contributor




      nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      nyholku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      marked as duplicate by Michael Homer, Sparhawk, muru, Mr Shunz, X Tian Apr 11 at 17:12


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Michael Homer, Sparhawk, muru, Mr Shunz, X Tian Apr 11 at 17:12


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          1 Answer
          1






          active

          oldest

          votes


















          2














          For your particular case:



          #!/bin/bash
          LIBDIR="lib dir"
          LIBS=("lib1" "lib2")
          CMD=(./debug.sh)
          for LIB in "$LIBS[@]"
          do
          CMD+=(-I "$LIBDIR/$LIB")
          done
          "$CMD[@]"
          exit


          There are two arrays in use: LIBS for the library names, and CMD for the command itself. This will also work if there are other extra spaces. +=(...) concatenates the new items onto the end of an array, just like it concatenates the new string onto the end of a string. "$CMD[@]" expands to all the values of the array as individual words (not split on spaces). Why does my shell script choke on whitespace or other special characters? has more on the subject in general, and How can we run a command stored in a variable? in the specific.






          share|improve this answer





























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            For your particular case:



            #!/bin/bash
            LIBDIR="lib dir"
            LIBS=("lib1" "lib2")
            CMD=(./debug.sh)
            for LIB in "$LIBS[@]"
            do
            CMD+=(-I "$LIBDIR/$LIB")
            done
            "$CMD[@]"
            exit


            There are two arrays in use: LIBS for the library names, and CMD for the command itself. This will also work if there are other extra spaces. +=(...) concatenates the new items onto the end of an array, just like it concatenates the new string onto the end of a string. "$CMD[@]" expands to all the values of the array as individual words (not split on spaces). Why does my shell script choke on whitespace or other special characters? has more on the subject in general, and How can we run a command stored in a variable? in the specific.






            share|improve this answer



























              2














              For your particular case:



              #!/bin/bash
              LIBDIR="lib dir"
              LIBS=("lib1" "lib2")
              CMD=(./debug.sh)
              for LIB in "$LIBS[@]"
              do
              CMD+=(-I "$LIBDIR/$LIB")
              done
              "$CMD[@]"
              exit


              There are two arrays in use: LIBS for the library names, and CMD for the command itself. This will also work if there are other extra spaces. +=(...) concatenates the new items onto the end of an array, just like it concatenates the new string onto the end of a string. "$CMD[@]" expands to all the values of the array as individual words (not split on spaces). Why does my shell script choke on whitespace or other special characters? has more on the subject in general, and How can we run a command stored in a variable? in the specific.






              share|improve this answer

























                2












                2








                2







                For your particular case:



                #!/bin/bash
                LIBDIR="lib dir"
                LIBS=("lib1" "lib2")
                CMD=(./debug.sh)
                for LIB in "$LIBS[@]"
                do
                CMD+=(-I "$LIBDIR/$LIB")
                done
                "$CMD[@]"
                exit


                There are two arrays in use: LIBS for the library names, and CMD for the command itself. This will also work if there are other extra spaces. +=(...) concatenates the new items onto the end of an array, just like it concatenates the new string onto the end of a string. "$CMD[@]" expands to all the values of the array as individual words (not split on spaces). Why does my shell script choke on whitespace or other special characters? has more on the subject in general, and How can we run a command stored in a variable? in the specific.






                share|improve this answer













                For your particular case:



                #!/bin/bash
                LIBDIR="lib dir"
                LIBS=("lib1" "lib2")
                CMD=(./debug.sh)
                for LIB in "$LIBS[@]"
                do
                CMD+=(-I "$LIBDIR/$LIB")
                done
                "$CMD[@]"
                exit


                There are two arrays in use: LIBS for the library names, and CMD for the command itself. This will also work if there are other extra spaces. +=(...) concatenates the new items onto the end of an array, just like it concatenates the new string onto the end of a string. "$CMD[@]" expands to all the values of the array as individual words (not split on spaces). Why does my shell script choke on whitespace or other special characters? has more on the subject in general, and How can we run a command stored in a variable? in the specific.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 11 at 4:48









                Michael HomerMichael Homer

                51k8141178




                51k8141178













                    Popular posts from this blog

                    getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                    Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                    Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.