I have one question in shell script for escape "\" with command substitution "` `". I post there to seek help to understand how it works.
My original one piece of code in script like this: This piece of code in whole script is working without errors
Usually if I want to escape $ sign from v$database, I should use "v\$database". Why is this piece of code using 3 backslash as v\\\$database? Is this because the backslash is in command substitution(backtick)? I tested in command line: only v\$database works, v\\\$database is not working. My Unix server is solaris 11.3 and SHELL is bash.
Please help me to understand why using 3 backslashes as escape. Thanks for your advice.
Moderator's Comments:
You have been asked to use code tags repeatedly over the years. This is your last warning. The next time you post without using code tags you will be banned from the site.
Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Yes it is because the command is backticks. This is one of the reasons to avoid using this deprecated form of command substitution. The preferred command substitution method uses $( ... ).
Try this instead:
This User Gave Thanks to Scrutinizer For This Post:
Did you consider - if no other expansion needs to be done within the here document - to switch off expansion therein (from man bash):
Quote:
Here Documents
. . . If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded.
Oracle Linux 5.6, 64-bit
Given the following snippet
wrkvar=`sqlplus -s / as sysdba <<EOF
set echo off feedback off head off trimsp on
select count(*) from v\$parameter
where name in ('db_file_name_convert','log_file_name_convert')
and value is not null;
EOF`
echo wrkvar=$wrkvarProduces... (2 Replies)
This is a bit off the wall, but I often need to run scripts where there are argument values that contain special characters.
For example,
$ ./process.exe -t M -N -o temp.mol.s -i ../molfiles/N,N\',N\'\'-trimethylbis\(hexamethylene\)triamine.mol && sfile_space_to_tab.sh temp.mol.s temp.s
It... (1 Reply)
mv myFile.txt myFile.txt.bak
sed s/foo/bar/g myFile.txt.bak > myFile.txt
Turn the two-line version, above, of the substitution commands into a shell script, subst1 taking three parameters:
the string to be replaced
the string with which to replace it
the name of the file in which to make the... (1 Reply)
Hi guys, I'm looking for some thoughts on this. I'm trying to do a clean 1 liner to substitute some values. What I have:
sed 's/Personid=.*/Personid=xxxxxx/' $tmpFileOut
sed 's/Person:.*/Person:xxxxxx/' $tmpFileOut
sed 's/PersonID:.*/PersonID: xxxxxx/' $tmpFileOut
Obviously that's a bit... (1 Reply)
Hey, guys!
Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek:
So, I wanted to use a command statement similar to the following.
This is kinda taken... (2 Replies)
I have a file that is a log file for web traffic. I would like to convert the timestamp in it to unix time or epoch time.
I am using the date command in conjunction with awk to try to do this. Just
myfile:
28/Aug/1995:00:00:38 1 /pub/atomicbk/catalog/home.gif 813
28/Aug/1995:00:00:38 1... (3 Replies)
I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename?
#!/bin/bash
filename=`echo $0`
/usr/bin/sed '/#include/ {
i\
the filename is `$filename`
}' $1
exit 0 (8 Replies)
The following statement does work. But the second command does not work as expected.
ssh root@123.123.123.123 \\"mysqldump -h localhost -u root -pPassWord dbName -d | gzip -cf\\" | gunzip -c > database1.sql
ssh root@123.123.123.123 \\"mysqlbinlog /var/log/mysql/mysql-bin.*... (0 Replies)
Hi,
What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution?
while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file
But,
while IFS='\n' read -r... (3 Replies)
"Is there any substituation of last command or script syntax which can be used as a user. As far I know the "last" command is being used to display information about previous logins. A member of adm group or the user adm can execute it only.
Thanks in advance for your usual help.
Ghazi (6 Replies)