Stripped argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stripped argument
# 1  
Old 09-28-2006
Stripped argument

Hi there

Has anyone seen this behaviour before, and if so, do they know why this happens? I am running this in BASH:

Code:
$ export DEV="/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk '{ print $6 }'"
$ echo $DEV
/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk '{ print }'

If you notice, the $6 argument has been stripped from the echo'd output.

Mike
# 2  
Old 09-28-2006
That's because the shell treat $6 as a commandline variable - it doesn't see the awk block and know it's an awk command:
Code:
$ export DEV="/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk '{ print \$6 }'"

FWIW - what you want here is probably an alias unless you plan to :
Code:
eval $DEV

# 3  
Old 09-28-2006
The value of the variable EXP is specified between ", so the shell interprets the value before affectation.
$6 is replaced by the value of argument 6 which seems to be be not set in your case.

Protect $6 with \ to avoid substitution:
Code:
export DEV="/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk '{ print \$6 }'"

or use simple quotes ', in that case internals simple quotes must be protected :
Code:
export DEV='/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk \'{ print $6 }\''


Jean-Pierre.
# 4  
Old 09-28-2006
mikie

I think its trying to expand the variable and since that variable is not intialized it is
replacing it with a BLANK.
see below

dam@athena:~$ echo '{ print $6 }'
{ print $6 }
dam@athena:~$ echo "'{ print $6 }'"
'{ print }'

not sure what the workaround is.
# 5  
Old 09-28-2006
Ahh, that explains it very well. Thank you both, Jim and Jean-Pierre.

Mike
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print all with along with stripped one column string

Hi, My output data from software tool is like 1234 84 test1 file:about user_detials(bankUser) :jpeg 10 40 xys 1356 2 branches dir:list of files(dirlisting:1) :directory 20 80 abc and want this to be printed as below. where first and last 3 columns along with the string which is in the... (6 Replies)
Discussion started by: ratheeshp
6 Replies

2. Shell Programming and Scripting

Inputs required in decoding file on AIX- executable (RISC System/6000) or object module not stripped

Hi, We are in the process of migrating from AIX to Linux. There is a script of type "executable (RISC System/6000) or object module not stripped" on AIX and we are unable to read the contents of it. Is there a way to read the contents of the file on AIX, so that we can rewrite the code in... (3 Replies)
Discussion started by: venkatesh17
3 Replies

3. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

4. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

5. SCO

New line being stripped from sed command

Hi, I am trying to insert text to the beginning of a text file with 'sed'. Its working however the new line is getting stripped. I have a variable with the text that I want to insert: VAR="This is the header line \n March 22, 2010 \n" sed "1i\\ $VAR" logfile >tmpfile The text gets... (3 Replies)
Discussion started by: nck
3 Replies

6. Shell Programming and Scripting

Replacing stripped off leading zeros in shell script

I have a script which is taking a 10 character variable (BOC) input by the user. If it begins with a zero, the script unwittingly strips that off, & passes a 9 characters variable. echo -n "Enter core-follow date/time for BOC: " setenv BOC $< The next bit of code picks up the 9... (4 Replies)
Discussion started by: wtaicken
4 Replies

7. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

8. Programming

xldb WARNING: libC.a(ansi_32.o) has been stripped

Hi, When i start the Debugger i get this warning: xldb WARNING: /usr/lpp/xlC/lib/libC.a(ansi_32.o) has been stripped. anyone know what this warning means? xldb is a Debugger under AIX. Lazzar (2 Replies)
Discussion started by: Lazzar
2 Replies

9. UNIX for Dummies Questions & Answers

Stripped install by floppy only.

I want to make an installation on a thinkpad 701C: 486/16Mb/500Mb. Except the kernel, I need support for program development in as many languages as possible but at least C/C++ and Lisp. My only choice is to install by floppy disks only. Which distribution should I choose, and are there any other... (2 Replies)
Discussion started by: Nietzsche
2 Replies
Login or Register to Ask a Question