LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-16-2010, 05:25 AM   #1
Panceisto
LQ Newbie
 
Registered: Mar 2010
Distribution: Debian
Posts: 12

Rep: Reputation: 0
question about bash script


HI all,

I ran into a bit of trouble making a bash script. Why does the following do what it does?

(Desktop is a directory, and I try to get it's modification date)

Code:
lamp:~# cmd='ls -l Desktop | grep -o "....-..-.. ..:.."'
lamp:~# $cmd
ls: cannot access |: No such file or directory
ls: cannot access grep: No such file or directory
ls: cannot access "....-..-..: No such file or directory
ls: cannot access ..:..": No such file or directory
Desktop:
total 4
-rw-r--r-- 1 root 11 2010-03-14 06:47 test

When I type in the command directly, without using an inbetween variable, it works fine.

Thanks,
Bart
 
Old 03-16-2010, 05:30 AM   #2
Maligree
Member
 
Registered: Mar 2008
Distribution: Gentoo, CentOS, Fedora, Arch
Posts: 231
Blog Entries: 1

Rep: Reputation: 42
Code:
eval $cmd
as to 'why?': http://fvue.nl/wiki/Bash:_Why_use_ev...e_expansion%3F

Last edited by Maligree; 03-16-2010 at 05:34 AM. Reason: but why?
 
1 members found this post helpful.
Old 03-16-2010, 05:40 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If not eval then
Code:
cmd1='ls -l Desktop'
cmd2='grep -o "....-..-.. ..:.."'
$cmd1 | $cmd2
 
1 members found this post helpful.
Old 03-16-2010, 06:35 AM   #4
Panceisto
LQ Newbie
 
Registered: Mar 2010
Distribution: Debian
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Maligree View Post
Thanks, exactly what I was looking for!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script CD question olan Linux - Newbie 6 11-06-2009 03:57 AM
bash script question jbraner Linux - General 5 08-10-2007 08:45 AM
bash script question soybean pete Linux - General 5 05-23-2007 12:33 PM
Bash script question deiussum Programming 6 08-14-2004 12:43 PM
bash script question xscousr Programming 5 07-03-2003 06:04 PM


All times are GMT -5. The time now is 10:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration