LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-23-2009, 11:30 AM   #1
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Rep: Reputation: 15
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.
 
Old 11-23-2009, 11:39 AM   #2
mail4vijay
Member
 
Registered: Oct 2009
Location: Delhi
Distribution: CentOS , RHEL
Posts: 214

Rep: Reputation: 33
Quote:
Originally Posted by Karas View Post
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":"`
 
Old 11-23-2009, 11:39 AM   #3
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by Karas View Post
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":"`

Last edited by rweaver; 11-23-2009 at 11:42 AM.
 
Old 11-23-2009, 04:53 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
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/
 
Old 11-23-2009, 05:11 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
"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.
 
Old 11-23-2009, 10:21 PM   #6
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
Quote:
Originally Posted by pixellany View Post
"Tickes" (actually back-tics) are deprecated. The preffered usage is $(<command-string>)
For reasons explained here.
 
Old 11-23-2009, 10:27 PM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

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


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
Running Commands from Ruby scripts... custangro Programming 2 10-05-2008 08:28 PM
Bash scripts do not echo commands sean@responsivedata. Linux - Newbie 9 01-17-2006 10:25 AM
Linux commands in shell scripts james_cwy Linux - Newbie 4 11-10-2003 01:14 AM
Running ftp commands in scripts john lee Linux - Newbie 4 05-07-2003 12:19 AM
Scripts won't run commands Xyphoid Linux - General 4 08-08-2002 08:49 PM


All times are GMT -5. The time now is 01:51 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