LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using commands in scripts (https://www.linuxquestions.org/questions/linux-newbie-8/using-commands-in-scripts-771021/)

Karas 11-23-2009 11:30 AM

Using commands in scripts
 
Hi all, I am just wondering how to use commands inside of a script.

In the code below, names is a variable.

Quote:

names=cat newusers.txt | cut -f1 -d":"
For some reason the cat command doesn't work, am I missing some characters?

Thanks.

mail4vijay 11-23-2009 11:39 AM

Quote:

Originally Posted by Karas (Post 3766904)
Hi all, I am just wondering how to use commands inside of a script.

In the code below, names is a variable.


For some reason the cat command doesn't work, am I missing some characters?

Thanks.


Tickes are missing.. use with
Quote:

names=`cat newusers.txt | cut -f1 -d":"`

rweaver 11-23-2009 11:39 AM

Quote:

Originally Posted by Karas (Post 3766904)
Hi all, I am just wondering how to use commands inside of a script.

In the code below, names is a variable.


For some reason the cat command doesn't work, am I missing some characters?

Thanks.

You're missing the ` character (unshifted ~ key, over by the 1)

Code:

names=`cat newusers.txt | cut -f1 -d":"`

chrism01 11-23-2009 04:53 PM

IOW, generically

x=a b c

means assign 'a b c' to x

x=`a b c`
means run the cmd a

x=$(a b c )

is the same.

Have a look at these
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

pixellany 11-23-2009 05:11 PM

"Tickes" (actually back-tics) are deprecated. The preffered usage is $(<command-string>)

Speaking to the thread title: Commands in scripts are the same as those typed in a terminal..the only difference is that--in a terminal--a long sequence of commands needs to be separated by ";"s (or use a "here document".)

You can enter commands one at a time and verify how they work---then combine them in a script.

catkin 11-23-2009 10:21 PM

Quote:

Originally Posted by pixellany (Post 3767313)
"Tickes" (actually back-tics) are deprecated. The preffered usage is $(<command-string>)

For reasons explained here.

i92guboj 11-23-2009 10:27 PM

Unless you require compatibility with the original bourne shell, since $() is a bashism.


All times are GMT -5. The time now is 08:12 PM.