Error with file test script


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Error with file test script
# 1  
Old 12-02-2018
Error with file test script

Dear friends

i am getting error when i run below script

Code:
#!/bin/bash
echo "Enter the name of the file"
read file_name
if [ -f $file_name ]
then
If [ -w $file_name ]
then
echo "add some text to quit ctrld"
cat >> $file_name
else
echo "the file does not have write permission"
fi
else
echo "$file_name does not exist"
fi
~

the error message is :
Code:
$ ./hello
Enter the name of the file
dddd
': not a valid identifier
./hello: line 16: syntax error: unexpected end of file

ibrahims@N-5CG613336K ~
$

any help please ? any advises as well how to debug such code or how to debug in general using vi editor is highly appreciated
# 2  
Old 12-02-2018
Moderator's Comments:
Mod Comment This is a duplicate f the problem raised in the thread Error code with if statement. Please continue any discussion on this topic there.

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If test script error: "Missing ]"

EDIT: Resolved Resolved by changing the first line to bash rather than csh, does bash and csh treat the brackets differently? Hi all, I'm doing to some basic stuff to teach myself "if" I've written the following: #!/bin/csh echo "This script checks for the test file" ... (1 Reply)
Discussion started by: Meshuggener
1 Replies

2. Shell Programming and Scripting

Test file script - if evaluation failing

I have a following script to evaluate if file exist in the directory and then archive it. #!/bin/bash #master directory scriptdir="/flex/sh/interfaces" #change this path only - all other paths are connected with it filedir="/flex/interfaces" #change this path only - all other paths are... (3 Replies)
Discussion started by: viallos
3 Replies

3. Shell Programming and Scripting

modify the test file by any script

Hi All the Helpers! I have a text file which looks like input.txt.I would request to please suggest me how can I make this file look like output.txt input.txt VOP 111 0 1 2 DEM 111 0 222 333 444 555 DEM 879 888 987 888 989 DEM 879 888 987 888 989 VOP 118 0 12 3 6... (7 Replies)
Discussion started by: Indra2011
7 Replies

4. Shell Programming and Scripting

Shell script that check the argument passed to it and prints error if test condition is not met

I want to make a script that check for the argument passed to it and generates an error in case any character/string argument passed to it. I am using below code, but its not working. can anyone help. #!/bin/bash if ]; then echo 'An integer argument is passed to the script hence... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

5. Shell Programming and Scripting

if test in bash - can't see error

Hi, I have the following script under bash if ; then echo File $file_name Not Found else echo File $file_name Found fi I get the message even the file is found; there is only one file with that name in the directory I can't figure... (4 Replies)
Discussion started by: f_o_555
4 Replies

6. UNIX for Dummies Questions & Answers

Test: argument expected error in shell script

Hi, I am trying to write a small script that validates if there exist files that start with a pattern in a given directory. Below is the piece of my script: #!/usr/bin/ksh BTFDIR=/opt/ships/temp if then echo 'found' else echo 'not found' fi When I run this... (2 Replies)
Discussion started by: snvniranjanrao
2 Replies

7. UNIX for Dummies Questions & Answers

error with TEST command

Hi, I have written a script to compare 2 string values.. below is the script.. it throws an error - ./compare_str.sh: test: amount1|amount2: unknown operator.. as both are string values, I am using a = operator in the test command. can some one help me figure out where the issue is?... (11 Replies)
Discussion started by: Vijay81
11 Replies

8. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

9. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

10. Shell Programming and Scripting

Test File Reading & Validation using Shell script

Please help develop script for below requirement -------Sample file------------------------------- HSVSHOSTRECON 20090115011817BP DARMAR60064966247003504720000000000000000000066626000000000000133000003D003463001332 ... (14 Replies)
Discussion started by: niraj_bhatt
14 Replies
Login or Register to Ask a Question