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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-23-2009, 11:30 AM
|
#1
|
Member
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49
Rep:
|
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.
|
|
|
11-23-2009, 11:39 AM
|
#2
|
Member
Registered: Oct 2009
Location: Delhi
Distribution: CentOS , RHEL
Posts: 214
Rep:
|
Quote:
Originally Posted by Karas
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":"`
|
|
|
|
11-23-2009, 11:39 AM
|
#3
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep:
|
Quote:
Originally Posted by Karas
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.
|
|
|
11-23-2009, 05:11 PM
|
#5
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
"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.
|
|
|
11-23-2009, 10:21 PM
|
#6
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by pixellany
"Tickes" (actually back-tics) are deprecated. The preffered usage is $(<command-string>)
|
For reasons explained here.
|
|
|
11-23-2009, 10:27 PM
|
#7
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083
|
Unless you require compatibility with the original bourne shell, since $() is a bashism.
|
|
|
All times are GMT -5. The time now is 01:23 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|