On the other hand, there are some tools that present a space as \ ; even some shells do that.
The explanation for this is easy:
The shell uses space characters as field delimiters. A script called in the form
will interpret "arg1" as the first argument and "arg2" as the second. The reason is that the shell splits its input line into three "words", interprets the first as a command, then feeds this the second and third as arguments 1 and 2.
If you want to include such a separator character into your regular argument you have to somehow tell the shell to ignore its special function and treat it as a normal character. There are two ways to do so: quoting and escaping.
Quoting means to enclose text parts into double or single quotes. Every special character loses its special meaning inside such a quoted string. Double quotes leave some of these special characters in place (like "*"), single quotes remove the special meaning from all characters. Btw.: the single and double quote characters also lose their special meaning - to introduce or close a quoted string - inside a quoted string:
is NOT a single quoted string inside a double-quoted string, but a double-quoted string, containing some single quotes. The same the other way round.
This makes it possible to send the script above one single argument containing a space char. Here it is:
This will call the script "script.sh" and feed it one argument, "arg1 arg2", because the shell ignores the field-separating power of the space char inside the quoted string. Use single instead of double quotes and the effect is the same, because both sorts of quoting have the same effect on space chars.
Save for quoting there is one other option: escaping. Escaping means to prepend a character with a backslash ("\") which works like (single-) quoting, but only for the character immediately following. The following are equal:
Will work the same way like example 1, because the escaped characters "a", "r", "g" and "1" have no special powers which could be stripped from them, neither by quoting nor by escaping.
You probably know by now how to combine the two arguments into one: escape the space:
This is why some shells include this automatically when they do TAB-completion. A "cd"-command int a directory "/foo/bar baz/" will work that way:
Your error was to "overdo" it: putting a variable into double-quotes already "escapes" its whole content, therefore the - additionally escaping "\" was taken to be meantt literally. Either use the backslash and remove the quotes or (the better solution) let the quotes in place but remove the escaping char.
hi All
I have a file that has 4 lines:
1. yesterday's date (mm/dd/yyyy)
2. yesterday's day- dd
3. yesterday's month- mm
4. yesterday's year- yyyy
I want to read this file and place them in variables. how can I do this.
Please help.
thanks in advance!!
KS (3 Replies)
Hello everybody,
I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
cat myname.txt
John Doe I
John Doe II
John Doe III
-----------------------------------------------------------------------
for i in `cat myname.txt`
do
echo This is my name: $i >> thi.is.my.name.txt
done
-----------------------------------------------------------------------
cat... (1 Reply)
Hello,
So I sorted my file as I was supposed to:
sort -n -r -k 2 -k 1 file1 | uniq > file2
and when I wrote
> cat file2
in the command line, I got what I was expecting, but in the script itself
...
sort -n -r -k 2 -k 1 averages | uniq > temp
cat file2
It wrote a whole... (21 Replies)
Hi All,
I've got a script to output YAML data, and I want to display data that's held inside variables inside one large CAT area. What's the easiest way to do this?
cat << "END"
---
classes:
- general_image
- $intro #Variable 1
- $mid #Variable 2
... (2 Replies)
Hi All,
i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way??
#!/bin/ksh
##script is sample.ksh
age=$1
gender=$2
class=$3
.
.
.... (3 Replies)
Below are three variables, which I want to pass into variable RESULT1
username1=userid
poihostname1=dellsys.com
port1=8080
How can I pass these variables into below code...
RESULT1=$((ssh -n username1@poihostname1 time /usr/sfw/bin/wget --user=sam --password=123 -O /dev/null -q... (4 Replies)