开发者

echoing asterisk to file

开发者 https://www.devze.com 2023-04-12 16:44 出处:网络
I have an odd problem.I\'m trying to echo the response from a file into another file.For instance I like to use:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消