Let's say there is one script s1
, and I need to pass argument $1
with value foo bar
, with space in it. This can be done
./s1 "foo bar"
however, when I want to run the above command in another script (say s2
), how should I put it? If I put it as above, foo bar
will be interpreted as two arguments (to s1) rather than one.
Note : You pass all the command line arguments separated by a space, but if argument itself has a space then you can pass such arguments by putting them inside double quotes “” or single quotes ”.
The G command appends a newline and the hold space to the end of the pattern space. Since, by default, the hold space is empty, this has the effect of just adding an extra newline at the end of each line. The prefix $! tells sed to do this on all lines except the last one.
To cd to a directory with spaces in the name, in Bash, you need to add a backslash ( \ ) before the space. In other words, you need to escape the space.
Filename with Spaces in Bash A simple method will be to rename the file that you are trying to access and remove spaces. Some other methods are using single or double quotations on the file name with spaces or using escape (\) symbol right before the space.
You can try quoting $1
:
./s2 "$1"
Use single quotes.
./script 'this is a line'
To consider variable substitutions use double quotes
./script "this is a line"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With