"Missing ]" error and other problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "Missing ]" error and other problems
# 1  
Old 03-12-2009
"Missing ]" error and other problems

hey guys, I've written this script to read a file from a cd and if the cd file isn't present, I want it to check the floppy drive for that same file, if the floppy drive does not have it I want to return a statement saying no disk found. It also copies files and so forth if the files are available but that stuff is working fine, its the actual if then statements that don't cycle right. Here is my code so far but when I put whitespace between "if" and "[" if gives me the "missing ]" error which does away if I delete the spaces. however when i get it running correctly It does every sequence of steps in order instead of following my if then commands. for example, I will put my output under the code.

Code:
#!/bin/sh

cd /ANIMALS
cp -r TIGERS TIGERS_QA
chmod 777 TIGERS_QA 
echo ======Finished backing up files======
#******************************************************************************
# Determine whether a CD or floppy disk was inserted, then proceed to 
# according tasks 
#
# ***CD VERSION***
# Copy .tgz file from cd to hard drive and extract folder to replace  
# current files.
#******************************************************************************
cd ..
if [ -f cdrom/TIGERS.tgz ]
    then 
        cp -r cdrom/TIGERS.tgz ANIMALS/TIGERS.tgz    
        cd ANIMALS
        tar xvf TIGERS.tgz 
        chmod 777 TIGERS.tgz
        echo ======Finished searching for cd====== 
#******************************************************************************
# ***FLOPPY VERSION***
# Copy .tgz file from floppy disk to hard drive and extract folder to  
# replace current files.
#******************************************************************************
cd ..  
elif [ -f dev/TIGERS.tgz ]
    then    
        cp -r dev/TIGERS.tgz ANIMALS/TIGERS.tgz    
        cd ANIMALS
        tar xvf TIGERS.tgz
        chmod 777 TIGERS.tgz
        echo ======Finished searching for floppy disk files======    
else 
    echo ======Insert CD or Floppy Disk======
fi


OUTPUT(with white spaces removed after if):
Code:
Install_Tigers
cp: cannot access TIGERS
chmod: WARNING: can't access TIGERS_QA
======Finished backing up files======
if[-f: No match
then: Command not found
tar: blocksize = 0
======Finished searching for cd======
elif[-f: No match
then: Command not found
tar: blocksize = 0
======Finished searching for floppy disk files======
else: endif not found

If I replace fi with endif I get the final statement also which says
======Insert CD or Floppy Disk======
However I only want this statement if the file cannot be found in the cd or floppy drives. which is not what it does, it shows it everytime.

Last edited by Franklin52; 03-12-2009 at 11:08 AM.. Reason: adding code tags
# 2  
Old 03-12-2009
Code:
#!/bin/sh
SRC=""
cd ..
if [[ -f cdrom/TIGERS.tgz ]] ; then 
   SRC=cdrom/TIGERS.tgz
fi
if [[ -f dev/TIGERS.tgz && -z "$SRC" ]] ; then
   SRC=dev/TIGERS.tgz 
fi 
if [[ -z "$SRC" ]] ; then    
      echo "file not found"
      exit 1
fi
cp "$SRC" ANIMALS/TIGERS.tgz 
cd ANIMALS
tar xvf TIGERS.tgz 
chmod 777 TIGERS.tgz
echo "done"
exit 0

Try this to start with.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

Problems with "write" and "wall"

Hello, I am using VirtualBox to simulate a small network with two Linux computers, the host is Mac OS X. My problem is that I can't send "write" and "wall" messages from the host to one of those Linux computers. Here is what works: - The virtual Linux computer answers "ping" messages that have... (5 Replies)
Discussion started by: 123_abc
5 Replies

6. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. HP-UX

ERROR: more than one instance of overloaded function "vprintf" has "C" linkage

Hi people! I've got this own library: -------------------------------------------- Personal.h -------------------------------------------- #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdarg.h> #include <string.h> ... (0 Replies)
Discussion started by: donatoll
0 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question