Visit Our UNIX and Linux User Community


Find error in the shell script file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find error in the shell script file
# 1  
Old 01-29-2013
Find error in the shell script file

Code:
echo "******Select Option:******"
echo "1 - script1"
echo "2 - script2"
echo "3 - script3 "
read option
echo "You have selected" $option"." 
if["$option"="1" ]
then /scratch/username/script1.sh
elif[ "$option"="2" ]
then /scratch/username/script2.sh
elif[ "$option"="3" ]
then /scratch/username/script3.sh
else
echo "Please try again from given options only."
fi



It gives following error :


Code:
line7 if[2=1]: command not found
line8 :syntax error near unexpected token `then'
line8 : `then /scratch/username/script1.sh'

Please help!

Last edited by Scrutinizer; 01-29-2013 at 05:40 AM.. Reason: extra code tags
# 2  
Old 01-29-2013
Fix your syntax errors - for example - change

Code:
if["$option"="1" ]

to

Code:
if [ "$option" = "1" ]

and so on
# 3  
Old 01-29-2013
what is the issue with then?

It dint change the errors. what is the issue with then?
# 4  
Old 01-29-2013
give space between if and [
Code:
if [ "$option" = "1" ]

post your modified script and error
# 5  
Old 01-29-2013
So - after fixing the line I specified you still see:

Code:
line7 if[2=1]: command not found

?

If you fix the other lines and put spaces in the right places it all works:

Code:
[root@host ~]# ./foo.sh
******Select Option:******
1 - script1
2 - script2
3 - script3 
1
You have selected 1.
script 1
[root@host ~]# ./foo.sh
******Select Option:******
1 - script1
2 - script2
3 - script3 
2
You have selected 2.
script 2
[root@host ~]# ./foo.sh
******Select Option:******
1 - script1
2 - script2
3 - script3 
3
You have selected 3.
script 3

Cheers,
ZB
# 6  
Old 01-29-2013
Yes even then the errors remain same.
This one being at the top
Code:
line7 if[2=1]: command not found

# 7  
Old 01-29-2013
After changing the line to

Code:
if [ "$option" = "1" ]

it doesn't - as I've tested it (and it's the correct syntax for bash - yours is not).

As previously requested - post your modified script, with the fixes we've suggested, and the output you are seeing. Then we can advise further.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #844
Difficulty: Medium
Bittorent, Gnutella and other distributed file transfers systems use do not user peer-to-peer, by default.
True or False?

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Shell script to find file type

1. The problem statement, all variables and given/known data: Write a shell script that takes a single command line parameter, a file path (might be relative or absolute). The script should examine that file and print a single line consisting of the phrase: Windows ASCII if the files is an... (4 Replies)
Discussion started by: kwatt019
4 Replies

2. Shell Programming and Scripting

How to find invalid URL in a text file using shell script?

How to find and remove invalid URLs in a text file using shell script? (1 Reply)
Discussion started by: vel4ever
1 Replies

3. UNIX for Dummies Questions & Answers

Shell script find word from one file and insert in another file

Hi, I am new to shell scripting. I need a bash shell scripts which search and grep a parameter value from input.txt file and insert it in between two semicolon of second line of output.txt file. For example The shell script search an IP address as parameter value from input.txt ... (2 Replies)
Discussion started by: sunilkumarsinha
2 Replies

4. Shell Programming and Scripting

Shell Script Find in File

Right, noob to shell scripting, playing a round for practice, wrote the following but it doesn't seem to work as expected, how could I fix/improve this script? #!/bin/bash #set -v #set -x case $# in 1) echo Searching for $1 in '*'; find . -iname '*' 2>/dev/null | xargs grep "$1" -sl... (3 Replies)
Discussion started by: Pezmc
3 Replies

5. Shell Programming and Scripting

Shell script to find specific file name and load data

I need help as to how to write a script in Unix for the following: We have 3 servers; The mainframe will FTP them to a folder. In that folder we will need the script to look and see if the specific file name is there and load it to the correct table. Can anyone pls help me out with... (2 Replies)
Discussion started by: msrahman
2 Replies

6. Shell Programming and Scripting

How to find yesterdays file - shell script

Hey guys - i have a script (below) that searches for current files in a particular directory. However i was wondering how to make it search for "yesterdays" file. For instance it looks for a file from yesterday and no older than that. I used stat command to check for file information: ... (6 Replies)
Discussion started by: DallasT
6 Replies

7. UNIX for Dummies Questions & Answers

shell script to find noof characters in a file name

hiiii shell script to find noof characters in a file name, when you run ls -l (using awk) I tried with this ls -l > temp awk -F"," '{print $1 " " expr length $9}' temp but it give some other value instead of file name length (error value like , 563,54,55,56....).How to prnint the... (10 Replies)
Discussion started by: krishnampkkm
10 Replies

8. Shell Programming and Scripting

Korn Shell Script to find out error in logfile

Hi All, I am new to this forum as well as to unix scripting. Can you please help me to create a korn shell script to find out errors in logfiles and get the name of that logfile ( which is having error) in email and email it to me? (2 Replies)
Discussion started by: jithu
2 Replies

9. Shell Programming and Scripting

Script Error: 13192.sumr: 0403-016 Cannot find or open the file.

Hello, i am familiar enough with unix to do some damage but thats about it. We have a set of RS/6000 43P Model 150's running AIX for our Catia V4 programmers. back in the 90's a script was written to automate the conversion of files into machine code. that script has started giving us... (0 Replies)
Discussion started by: jgruenwald
0 Replies

10. Shell Programming and Scripting

Shell script to Find file size

Hi, I am writing a script which takes the input file name and concat as a new file by appending a "1" to the file name. However i am not able to get the size of this new file. I am not sure where i am going wrong. Please check the script and help me get this working. #!/bin/sh ... (1 Reply)
Discussion started by: ragsnovel
1 Replies

Featured Tech Videos