Execution problems with BASH Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution problems with BASH Shell Script
# 1  
Old 09-12-2011
Error Execution problems with BASH Shell Script

Hi

I need help with my coding , first time I'm working with bash .

What i must do is check if there is 3 .txt files if there is not 3 of them i must give an error code , if al three is there i must first arrange them in alphabetical order and then take the last word in al 3 of the .txt files and put the words into a temp .txt file

but i cannot get this right . i get error ambiguous redirect

Here is the code
Code:
#!/bin/sh
        if [ -f $1 ] && [ -f $2 ] && [ -f $3 ]
                then
                        sort < $1 > mySortedFile.txt
                        tail -1 < mySortedFile.txt > myTailed1.txt
                        sort < $2 > mySortedFile1.txt
                        tail -1 < mySortedFile1.txt > myTailed2.txt
                        sort < $3 > mySortedFile2.txt
                        tail -1 < mySortedFile2.txt > myTailed3.txt
                        sort -r < myTailed1.txt > finalSort.txt
                        sort -r < myTailed2.txt >> finalSort.txt
                        sort -r < myTailed3.txt >> finalSort.txt
                        cat finalSort.txt
                else
                        if [ "$1" == colours.txt ] && [ "$2" == fruit.txt ]
                                then
                                        echo "Error number.txt missing"
                        elif [ "$1" == colours.txt ] && [ "$3" == number.txt ]
                                then
                                        echo "Error fruit.txt missing"
                        elif [ "$2" == fruit.txt ] && [ "$3" == number.txt ]
                                then
                                        echo "Error colour.txt missing"
                        elif [ "$1" == colour.txt ]
                                then
                                        echo "Fruit and Number is missing"
                        elif [ "$2" == fruit.txt ]
                                then
                                        echo "Colour and Number is missing"
                        elif [ "$3" == number.txt ]
                                then
                                        echo "Colour and Fruit is missing"
                        fi
        fi

sorry for my bad English

Regards
Shaun
# 2  
Old 09-12-2011
Seems to need no command line arguments, as it assumes what they are . . . .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script problems int to binary

Hi, I am trying to do a bash script that convert a decimal number to a binary value, but it doesn't work... To begin, I am just trying to convert a positive number to 8 bits binary. read -p"Entrez un nombre entre -128 et 127 pour l'encoder en binaire: " number binaryValues=(128 64 32 16 8 4 2... (8 Replies)
Discussion started by: Zedki
8 Replies

2. Shell Programming and Scripting

sed problems - Bash Script

Hi I keep getting the following error sed: -e expression #1, char 32: unterminated `s' command sed: -e expression #1, char 35: unterminated `s' command sed: -e expression #1, char 35: unterminated `s' command whenever I use the following bash script #! /bin/bash... (2 Replies)
Discussion started by: spbr
2 Replies

3. Shell Programming and Scripting

Bash script having variable substitution problems

Hi I am setting the variables like this : setenv MODULE1 modem5__3 setenv MODULE2 modem5__2 setenv MODULE3 modem_ctrl_1_1 setenv MODULE4 modem_1_0 setenv COUNT 10 I am having a bash script as shown below ################################################ #!/bin/bash for ((... (5 Replies)
Discussion started by: kshitij
5 Replies

4. Shell Programming and Scripting

Copying large files in a bash script stops execution

Hello, I'm new to this forum and like to first of all say hello to everyone. I've got a really annoying problem at the moment. I'm trying to rsync some files (about 200MB with one file of 120MB) from a Raspberry PI with raspbian to a debian server via rsync. This procedure is stored in a... (3 Replies)
Discussion started by: wex_storm
3 Replies

5. Shell Programming and Scripting

Expect script Execution Problems .. Help!!!

Hi Guys, I am writing the expect script which take input from the txt file and check whether that file is present over the Sftp or not.If yes then delete other wise check the next one.. I am able to do comparison online for single file... Please also note still i didn't try to implement... (1 Reply)
Discussion started by: hackerdilli
1 Replies

6. AIX

SH Script Execution Problems with Cronjob

Hi, I have created a sh script to startup and shutdown the oracle database, when I execute the script thru command line it execute successfully, but when I call the script thru cronjob it does not execute. The scripts are as follows: LOG=/oracle/times.log export ORACLE_SID=prod echo... (6 Replies)
Discussion started by: lodhi1978
6 Replies

7. Shell Programming and Scripting

Execution Problems with bash script

Hello, can someone please help me to fix this script, I have a 2 files, one file has hostname information and second file has console information of the hosts in each line, I have written a script which actually reads each line in hostname file and should grep in the console file and paste the... (8 Replies)
Discussion started by: bobby320
8 Replies

8. Shell Programming and Scripting

execution time / runtime -- bash script please help!

Hello, I'm running a bash script and I'd like to get more accurate a runtime information then now. So far I've been using this method: STARTM=`date -u "+%s"` ......... *script function.... ......... STOPM=`date -u "+%s"` RUNTIMEM=`expr $STOPM - $STARTM` if (($RUNTIMEM>59)); then... (6 Replies)
Discussion started by: TehOne
6 Replies

9. OS X (Apple)

Execution Problems with ASU Shell Script

Hello. I have been trying to create a shell script that checks to see if there are software updates and if not, then exit the script. If so, then check to see if a user is logged in. If a user is logged in, it will only install the updates. If a user is not logged in, then it will display a... (3 Replies)
Discussion started by: Talcon
3 Replies

10. Shell Programming and Scripting

bash script execution with a variable in a single line

Let a script needs a variable to execute. For example if i run ./test.sh then it needs a variable as there is a <STDIN> in the script. I want to execute it as in command line. Let test.sh requires a variable name $number I want to execute it by >test number <enter> how is it possible? (1 Reply)
Discussion started by: shoeb
1 Replies
Login or Register to Ask a Question