variable help in bash


Forum: Programming and Scripting
Topic: variable help in bash
started by: plinej

Posted by plinej on July 18 2006,18:58
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!

Posted by mikshaw on July 18 2006,20:15
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
}

Posted by plinej on July 18 2006,20:44
thanks again mikshaw! A function is what I wanted.
Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.