I've got some command outputs saved into variables in bash script, for instance 3, in each loop iteration. I'd like to save these variables inside a plain text database containing 3 fields before the iteration finishes

The idea is the following:


Command output1 > $v1
Command output2 > $v2
Command output3 > $v3

echo $v1 $v2 $v 3 >> database.txt


Would the echo variable calling be valid for storing variables value into database.txt? What if we would like them to be delimited by tab in the plain text?

  • 1
    What do you actually want to achieve? Why do you want to store variables in the text file? How do the variables look like? Can you give a more concrete example?
    – michas
    Commented Dec 8, 2016 at 6:27

2 Answers 2


In a similar project i built, this one worked for me fine:

export TMPFILE=/tmp/yadvalues

function listselect { 
echo "Args Received = $0, $1 , $2 , $3 , $4 , $5" #Display args send to function 
echo -e "FILEID=\"$1\"\nFILENAME=\"$4\"\nFILECOMMAND=\"$5\"" > $TMPFILE
# Save some of the args in file
#export -f listselect

function filedisplay { 
source $TMPFILE 
ftd=$(yad --title="File Display-$FILENAME" --width=800 --height=500 \
--center --text-info --filename=$FILENAME --wrap --editable \
--button="Go Back":0)    
# Use var $FILENAME present in $TMPFILE
#export -f filedisplay

The code you posted would capture the standard output of Command into filenames based on the values of the $v1 & etc variables. If that is what you are doing, then: no, the echo statement at the end would not produce the contents of those three files, but rather the three file names.

If you want the output of those three commands to be saved, tab-delimited, into the database.txt file, then do something like:

printf "%s\t%s\t%s\n" "$(Command output1)" "$(Command output2)" "$(Command output3)" >> database.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .