Using echo to create a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using echo to create a script
# 1  
Old 06-23-2009
Using echo to create a script

Hello all,

I want to be able to create a script on the fly from another script by echoing lines into a file, but am running into difficulty, as it isn't working right. What am I doing wrong?

Code:
echo "for i in `grep $FRAME /root_home/powermt.sort.fil |awk '{print $7}'`" > pvtimout_set.sh
echo "do" >> pvtimout_set.sh
echo "echo ${i} ----------" >> pvtimout_set.sh
echo "echo pvchange -t 90 /dev/dsk/${i}" >> pvtimout_set.sh
echo "pvchange -t 90 /dev/dsk/${i}" >> pvtimout_set.sh
echo >> pvtimout_set.sh
echo "echo pvdisplay /dev/dsk/${i} |grep Timeout" >> pvtimout_set.sh
echo "pvdisplay /dev/dsk/${i} |grep Timeout" >> pvtimout_set.sh
echo >> pvtimout_set.sh
echo "done 2> /root_home/scripts/pvtimout.out 1>&2" >> pvtimout_set.sh

Thanks for any help in advance!
# 2  
Old 06-23-2009
Quote:
Originally Posted by LinuxRacr
...
What am I doing wrong?
...
Escape those accent graves with a backslash character each.

tyler_durden
# 3  
Old 06-23-2009
The problem is caused by not escaping characters which will be interpreted by the shell (e.g. dollar and backtick ... and maybe more) where you want them to appear in the new script. It might be easier to write the script in the normal manner and call it with a parameter.

If you persist with this approach, test thoroughly before executing the new script.

The lines starting ... echo "echo ... need attention to stop the pipe becoming active in the new script because the echoed string will not be in quotes.
# 4  
Old 06-23-2009
Thanks! Here is what I did, based on some help I received:
Code:
cat <<-EOF! > pvtimeout_set.sh
for i in \`grep ${FRAME} /tmp/powermt.sort.out |awk '{print \$7}'\`
do
echo \${i} ----------
echo pvchange -t 90 /dev/dsk/\${i}
pvchange -t 90 /dev/dsk/\${i}
echo pvdisplay /dev/dsk/\${i} |grep Timeout
pvdisplay /dev/dsk/\${i} |grep Timeout
echo
done
EOF!

# 5  
Old 06-23-2009
FYI:
Code:
     << [-]word
           The shell input is read up to a line that is the  same
           as word, or to an EOF. No parameter substitution, com-
           mand substitution, or file  name  generation  is  per-
           formed  on  word.  The  resulting  document,  called a
           here-document, becomes  the  standard  input.  If  any
           character  of  word  is  quoted,  no interpretation is
           placed upon the characters of the document. Otherwise,
           parameter  and command substitution occur, \NEWLINE is
           ignored, and \ must be used to quote the characters \,
           $,  `,  and  the  first  character  of  word.  If - is
           appended to <<, then all  leading  tabs  are  stripped
           from word and from the document.

# 6  
Old 06-29-2009
Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script: Echo continuation across many lines

I am writing a bash script that automatically generates a macro program. I want to have an echo on multiple lines and getting an error /home/chaos/instru-correct.sh: line 309: command line is: command not found I am using echo "# The general synopsis of the $mfl" \ ... (2 Replies)
Discussion started by: kristinu
2 Replies

2. Shell Programming and Scripting

Echo command not working in the script

HI I have and echo command which works perfectly in the shell but when i execute in the script it gives me an error code query is as below QUERY=`echo "Select Severity,Dupl_count,Creation_Time,Last_Received,Node_Name,Node_Name,Object,Message_Group,Message_Text,Last_Annotation from " \ ... (2 Replies)
Discussion started by: Jcpratap
2 Replies

3. UNIX for Dummies Questions & Answers

Meaning of script with echo, -d, -f1, -f2

Hello Friends, I am a new learner of Unix & need to understand below script as start up, Can anyone explain the meaning of each line listed below. Thanks for your time. #!/usr/bin/ksh PARAMS=$1 #echo "parms passed is $PARAMS @" STATUS=`echo ${PARAMS} | cut -d: -f1` JOBNAME=`echo... (9 Replies)
Discussion started by: DK2014
9 Replies

4. Shell Programming and Scripting

Echo backspace in spinner script

Trying to insert a backspace for echo. while true ; do i='-\|/' for j in 1 2 3 4 do echo -ne "$(echo ${i} | cut -c${j})" sleep 1 done done this currently outputs: -\|/-\|/-\|/-\| .....etc ---------- Post updated at 02:34 PM ---------- Previous update was at 02:10 PM... (7 Replies)
Discussion started by: squrcles
7 Replies

5. Shell Programming and Scripting

Shell Script if $2 is greater than 10 then echo $1

Hi, I have a file output.txt 3258 14 32647 10 32649 10 32650 10 32651 10 32652 10 32653 10 32654 10 32655 10 32656 10 32515 09 32478 08 32555 08 35888 08 (4 Replies)
Discussion started by: amit_spl
4 Replies

6. Shell Programming and Scripting

printf/echo in a second script

This may be little confusing. I have Script1, which pulls data from the system and creates another script(lets say script2). While I run script1 I need to add printf/echo statements for script2, so that when I run script2 I see those statement. eg: script1 765 printf " display frame-$1 timeoffset... (2 Replies)
Discussion started by: miltonrods
2 Replies

7. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

8. Shell Programming and Scripting

echo prints nothing-shell script

could anyone tell me why when i execute the following script, echo returns blank set k = 1 echo $k (9 Replies)
Discussion started by: saman_glorious
9 Replies

9. Shell Programming and Scripting

create array holding characters from sring then echo array.

Hi, I wish to store $string1 in $string1array a character in each array element. Then i wish to echo the entire array to the screen so that it reads as the normal string again. I have been trying with the code below but does not work. Please help... To put string into array: ... (5 Replies)
Discussion started by: rorey_breaker
5 Replies

10. UNIX for Advanced & Expert Users

run a shell script with echo

I need to schedule a shell script that runs at the command prompt to run with crontab. When I run this at the command prompt as follows it works: echo /usr/test/script.sh date1 date2 y | at 20:00 But if I will pass these argument (date1, date2, Y) with in a shell script (say scr1.sh) and... (7 Replies)
Discussion started by: keerthi
7 Replies
Login or Register to Ask a Question