Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange command run 2

Status
Not open for further replies.

bluedragon2

IS-IT--Management
Jan 24, 2003
2,642
US
I run the command in UNIX:

ls -l filename | awk '{print $5}'

and get the file size returned.

I run this in perl:

$size = `ls -l filename | awk '{print $5}'`;

and get all the information about the file in the variable (ie $size equals -rwx------ 1 owner group 12300 /filename)

Does antone know why that is happening?

Thanks

Blue [dragon]

If I wasn't Blue, I would just be a Dragon...
 
Just a note, I got around it by putting ls -l filename into an array and spliting out the filesize.



Blue [dragon]

If I wasn't Blue, I would just be a Dragon...
 
The backticks don't protect the dollar sign inside the expression. The result is that the $5 evaluates as the 5th pattern match (probably null) is passed to the shell that way.
You need to escape the dollar sign to make it work the way you expect.

$size = `ls -l filename | awk '{print \$5}'`;
 
Read this (scroll down to qx/STRING/):
The short is you can make a backtick-like execute statement without interpolation if you need.

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Thanks...



Blue [dragon]

If I wasn't Blue, I would just be a Dragon...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top