Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: variable help in bash< Next Oldest | Next Newest >
plinej Offline





Group: Members
Posts: 75
Joined: Oct. 2005
Posted: July 18 2006,18:58 QUOTE

How would I make a variable equal to a chain of commands in a bash script?
I made a rather lengthy bash script but would like to shorten it up by somehow making a variable equal to a chain of commands that repeats itself numerous times in my script. Here's one of the few chain of commands I'm talking about:

echo "---------------------------------------------------" >> "$DVDARCHIVE"dvd-"$num"/moved.txt; echo "" >> "$DVDARCHIVE"dvd-"$num"/moved.txt

I tried googling but I couldn't figure out what I needed to do.

thanks for any help!
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: July 18 2006,20:15 QUOTE

To make the output of a single command into a variable:
Code Sample
VARIABLE=`command` #those are backticks, not single quotes
or
Code Sample
VARIABLE=$(command)


However, I think a function is more appropriate in your case, if you want multiple commands in it:
Code Sample
function_name(optional_parameters) {
command 1
command 2
command3
}


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
plinej Offline





Group: Members
Posts: 75
Joined: Oct. 2005
Posted: July 18 2006,20:44 QUOTE

thanks again mikshaw! A function is what I wanted.
Back to top
Profile PM 
2 replies since July 18 2006,18:58 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: variable help in bash

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code