ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi Everyone,
I am writing a shell script which reads another shell script one line at a time and executes them and if an error is encountered, it logs them in a log file. The shell scripts are as follows -
1. main script
-------------------------------------------------------------------------------------------------------------------------
#!/bin/sh
FILE=./tmpscript
LOGFILE=./log.txt
i=1;
declare -a name
num=`cat $FILE|wc -l`
{
while [ $i -le $num ]; do
read name[$i]
${name[$i]}
if [ $? = 1 ]
then echo [`date`] - $FILE :$i - ${name[$i]} Failed >>$LOGFILE
fi
let i+=1
done
} < $FILE
--------------------------------------------------------------------------------------------------------------------------
2. tmpscript
--------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
ls
echo "running test script"
echo "tests" > logic.txt
ls -l
ls kumar
# line of comment
--------------------------------------------------------------------------------------------------------------------------
So, the main script executes the script tmpscript one line at a time. Now the problem is the when it tries to run echo "tests" > logic.txt (line 4 of tmpscript), it does not execute properly. It is executed as "test">logic.txt and not as echo "test">logic.txt at the prompt and hence the logic.txt is not created. Can anyone please suggest me a solution for this.
I tried echo "12345">logic.txt and it didn't work...... The problem is while executing the command, the echo "12345" is executed first and hence the command becomes "12345" >logic.txt which is not proper . The whole command should execute at the same time
No ....actually my aim of using this command (echo "12345">logic.txt) is to create a temporary file during runtime which is to be used for further testing purpose . Thanks again for your answer.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.