![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Difference between using "echo" builtin and /bin/echo | ulidtko | Shell Programming and Scripting | 2 | 07-15-2009 12:12 PM |
| what does echo $$, $? $# mean | gokulagiridaran | Shell Programming and Scripting | 8 | 08-21-2008 01:22 PM |
| echo $0 | mainegate | Shell Programming and Scripting | 2 | 09-24-2007 02:34 AM |
| echo not echoing correctly | shorty | UNIX for Dummies Questions & Answers | 3 | 09-25-2006 05:45 PM |
| How to set echo on | siegfried | Shell Programming and Scripting | 1 | 11-18-2005 01:56 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to correctly use an echo inside an echo?
Bit of a weird one i suppose, i want to use an echo inside an echo... For example...
i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file Why is this not correct? Thanks. |
|
||||
|
echo "echo "hello"" >$file If you want only hello should be written to $file, then The command should be Code:
echo `echo "hello"` For mor ecample: Code:
echo "echo `date`" echo Thu Sep 10 08:15:31 EDT 2009 echo `echo \`date\`` Thu Sep 10 08:15:12 EDT 2009 |
|
||||
|
Quote:
1. As suggested earlier, either "escape" the double quotes surrounding "hello" or use single quote i.e. use Code:
echo "echo \"Hello\" " or echo "echo 'hello' " 2. By doing >$file two times the second echo (i.e. good bye) will over write $file. Instead use Code:
echo "echo 'goodbye'" >> $file to append the contents of the echo into the file. 3. It is a best practice to refrain from creating elaborate scripts using the echo command. Instead use shell "here documents" Code:
cat <<! > $file echo "Hello" echo "Good bye" ! is certainly a lot cleaner. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|