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;
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.
bash quoting
New contributor
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.
add a comment |
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.
bash quoting
New contributor
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.
add a comment |
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.
bash quoting
New contributor
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
bash quoting
New contributor
New contributor
edited Apr 11 at 5:18
Rui F Ribeiro
42.1k1483142
42.1k1483142
New contributor
asked Apr 11 at 4:37
nyholkunyholku
1
1
New contributor
New contributor
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.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
answered Apr 11 at 4:48
Michael HomerMichael Homer
51k8141178
51k8141178
add a comment |
add a comment |