I have an odd problem. I'm trying to echo the response from a file into another file. For instance I like to use:
# run_location=`find -name 'program.exe'`
# echo $run_location>storagefile.txt
So I can save where my program is located for use later. However now I have an issue 开发者_JAVA技巧where I want to grab the output of a program and store it. The only issue is that the output contains a lot of asterisks (*) and when I echo an * it echoes all of the filenames in my directory producing a file that is a mess.
The output of the file is:
# ./device -FD
*******************************
* Firmware : 1.0034 *
* Date : 011209 *
*******************************
And i would like to save the file verbose, is there any way around this? Possibly some other way to save the output to a file? I know it wasn't the best idea for them to output with asterisks, but I have no control over how I get this data back.
Thanks!
Important rule for shell scripting: be liberal where you apply your quotes. So for your example:
run_location="`find -name 'program.exe'`"
echo "$run_location" >storagefile.txt
Without these quotes, these get interpreted as command line tokens... It will be chopped up based on the presence of spaces, and patterns like *
will be evaluated. If it comes from the user, a file, or the output of a program, quote it.
精彩评论