LinuxQuestions.org
Help answer threads with 0 replies.
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: 167Reputation: 167
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: Rocky 9.2
Posts: 18,391

Rep: Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774Reputation: 2774
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: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
"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,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:23 AM.

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
Open Source Consulting | Domain Registration