I'm taking Unix Scripting course and we've been given the following command
What this command is basically doing is giving the lines in the ordinary file foo that contains the letter 't'.
From my understanding, command substation occurs first. So echo '\t' is executed first.
Now, the command looks like this
However, the double quotes don't save backslashes so the \t turns into just the character t which means now it is simply looking for that.
Now, this is what the question was about; to answer what the command is really doing.
However, I'm lost when I try to find a way to change this command to show simply \t
If I change the code to this
it still does the same thing.
However, when I change it to this
then it tries to find \t but I don't see why it needs three backslahes.
Can anyone explain the logic in why it needs three and not two backslahes?
Using double quotes the literal value of all characters enclosed is preserved, except for the dollar sign, the backticks (backward single quotes, ``) and the backslash.
The dollar sign and the backticks retain their special meaning within the double quotes.
The backslash retains its meaning only when followed by dollar, backtick, double quote, backslash or newline. Within double quotes, the backslashes are removed from the input stream when followed by one of these characters. Backslashes preceding characters that don't have a special meaning are left unmodified for processing by the shell interpreter.
A double quote may be quoted within double quotes by preceding it with a backslash.
What turk451 said is correct. To add just a bit more.....
You need to ultimately pass \\t to grep. If the search string given to grep has \t then grep will match a tab. Passing the double slant to grep is necessary to escape it such that grep treats it as a two character pattern.
Quote:
However, the double quotes don't save backslashes so the \t turns into just the character t which means now it is simply looking for that.
In this case the shell is passing the backslant, but it is grep that is interpreting it as a tab rather than two characters.
As for why you need three backslants...
When the shell sees \\\t it replaces the first two with a single slant, and because \t isn't a special case it leaves it alone resulting in \\t being passed to grep which is exactly what you need.
Last edited by agama; 10-05-2010 at 10:24 PM..
Reason: typo
Hello Experts,
I am still learning linux and have come across a question, hope to get some answer.
I have two servers, and both have the same version of svn client installed and both have the same user_id.
my SVN client version:
svn, version 1.6.11 (r934486)
compiled Mar 2 2011,... (4 Replies)
below is the output xml string from some other command and i will be parsing it using awk
cat /tmp/alerts.xml
<Alert id="10102" name="APP-DS-ds_ha-140018-componentFailure-S" alertDefinitionId="13982" resourceId="11427" ctime="1359453507621" fixed="false" reason="If Event/Log Level(ANY) and... (2 Replies)
Hi Experts,
I am very much new to linux scripting, I am currently working on reducing my manual work and hence writing a script to automate few task.
I am running below command to snmpwalk the router..
snmpwalk -v 3 -u WANDL_SU -a MD5 -A vfipmpls -x DES -X VfIpMpLs -l authPriv... (19 Replies)
Hi All,
I was looking for grep command option which can exactly matches the word in a file, for examples you may be seeing one word that is also in another word, there might be lkk0lv23 and a lkk0lv234 in which case lkk0lv23 will put BOTH hosts from the grep in.
I was using this in a bash... (2 Replies)
a) cd /root/user/dir/sd/disk
./runInstaller -silent -responseFile
b) cd /root1/user1
cp /root/user/dir/sd/disk/ram.txt
now a) executes and starts running but b) interupts a) and is executed while a) is running on the other hand
so I want b) to start only after successfull completion of... (6 Replies)
hi Guys!
My requirement is... I need to get notified if somebody executes a specific commands...like kill or httpd stop.... something like that....
can somebody help me out...
Regards,
kiran (8 Replies)
Hi all,
I want to display a progressbar depending upon the completion status of a command. I am coding from scratch as I dont want to use in place code. so Is there anyway of getting the progress of a command in percentage or in any other units while its running , is it possible using the top... (5 Replies)