I'm trying to get a script to execute from that's in my text.
The message that come up when I execute is bash: script.sh: command not found.Code:#!/bin/sh echo "Enter a file to search for: \c" read pname if [$pname = ""]; then echo "You must enter a file to search for .." echo "press any key to continue .." read press clear fi echo "Searching for $pname .. " find / -name $pname -print echo "Press any key to continue .." read press
I made it executable with command chmod +x script.sh.
I'm not familiar with all the statements in the srcript like fi but can you pinpoint what's wrong with the script?
Have you tried "./script.sh"?
Does this script look functional? I don't seem to get a response with command "press any key to continue.." but only by pressing return. Read press means to wait for any key press? If I type in a name, it lists a bunch of files with response permissions denied after each. When it finishes, it says press any key but only pressing return gets me back to a prompt.
read, as stated in the man page, reads a line ( NOT char ) from standard input - end of the line is where you press the return key.
I've tried ths again and still no luck getting it to work. The name of the script is findit. I dropped the \c in the first echo since it didn't seem to keep cursor on the same line and also added spaces within brackets, like this [ $pname = "" ].
My script looks like this now.
When I execute this script and don't type anything in and press enter. It works correctly and tells me "You must enter a file to search for!" and clears the screen and starts over again. When I typed a term in to search for, xwindows. I got the following errors.Code:#!/bin/sh printf "Enter a file to search for: " read pname if [ $pname = "" ]; then echo "You must enter a file to search for!" echo "press any key to continue ..." read press clear ./findit fi else echo "Searching for $pname ..." find / -name "$pname" echo "Press any key to continue ..." read press fi
./findit: line 4: [: xwindows: unary operator expected
./findit: line 12: syntax error near unexpected token 'else'
./findit: line 12: 'else'
./findit: syntax error near unexpected token 'else'
./findit: line 12: else
If anyone can tell me how to arrange the lines or correct the syntax to get this working I'd really appreciate it.
The mistake is on using if else condition
It should be
NotCode:if [] then .... else ..... fiThis is what the mistake I see....Code:if [] then ..... fi else .... fi
In linux Os (Especially 10.04 Beta ubuntu edition) it works fine... Totally fine...
Try to place your variables inside double quotes e.g. "$var"
You need to use == instead of =, as in
Code:#!/bin/sh echo "Enter a file to search for: \c" read pname if [$pname == ""]; then echo "You must enter a file to search for .." echo "press any key to continue .." read press clear fi echo "Searching for $pname .. " find / -name $pname -print echo "Press any key to continue .." read press
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks