The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ls and take each file as argument melanie_pfefer Shell Programming and Scripting 3 01-24-2007 09:10 AM
argument help brentdeback Shell Programming and Scripting 2 11-27-2005 03:53 PM
xldb WARNING: libC.a(ansi_32.o) has been stripped Lazzar High Level Programming 2 01-05-2004 02:22 PM
Stripped install by floppy only. Nietzsche UNIX for Dummies Questions & Answers 2 10-13-2002 09:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2006
mikie mikie is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 16
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 (permalink)  
Old 09-28-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
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 (permalink)  
Old 09-28-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,355
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 (permalink)  
Old 09-28-2006
systemsb systemsb is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 23
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 (permalink)  
Old 09-28-2006
mikie mikie is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 16
Ahh, that explains it very well. Thank you both, Jim and Jean-Pierre.

Mike
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0