0

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:

If..

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

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

fi

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 Dec 8 '16 at 6:27
0

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
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.