Bash Error Handling Command Not Found
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us bash error handling best practices Learn more about Stack Overflow the company Business Learn more about hiring developers or error handling in bash shell script posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is bash throw error a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can bash error checking answer The best answers are voted up and rise to the top Bash error: “[y command not found” [duplicate] up vote 1 down vote favorite This question already has an answer here: Brackets in if condition: why am I getting syntax errors without whitespace? 3 answers I am trying to get this script to function correctly but I get ./passmark.sh line 7: [y command not found. Here is my
Command Not Found Bash
script #!/bin/bash # A simple script to ask a user for a pass mark and then display a grade # the grade will be either an A, B, C, D or F # CONT=y echo while [$CONT = "y" ] do echo -e "\"Please enter a pass mark: \c \"" read MARK if [$MARK -ge "0" -a $MARK -lt "50"] ; then echo -e "\n \"F\" \n" elif [$MARK -ge "50" -a $MARK -lt "60"] ; then echo -e "\n \"D\" \n" elif [$MARK -ge "60" -a $MARK -lt "70"] ; then echo -e "\n \"C\" \n" elif [$MARK -ge "70" -a $MARK -lt "80"] ; then echo -e "\n \"B\" \n" elif [$MARK -ge "80" -a $MARK -lt "100"] ; then echo -e "\n \"A\" \n" else echo -e "\"Invalid input!!\n \"" fi echo -e "\"Would you like to enter another pass mark? (y/n) \c \"" read REPLY case "$REPLY" in n | N | no | No | NO ) CONT=n ;; *) ;; esac echo done bash shell-script share|improve this question edited Nov 10 '14 at 18:08 Braiam 16.8k95599 asked Oct 16 '14 at 22:04 Lyall Johnson 612 marked as duplicate by slm♦ Oct 16 '14 at 22:37 This question has been asked bef
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have
Bash Script Command Not Found
Meta Discuss the workings and policies of this site About Us Learn bash command not found windows more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Ask command_not_found_handle Ubuntu Questions Tags Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: http://unix.stackexchange.com/questions/162599/bash-error-y-command-not-found Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Every command fails with “command not found” after changing .bash_profile? up vote 14 down vote favorite 4 I was updating my .bash_profile, and unfortunetly I made a few updates and now I am http://askubuntu.com/questions/186808/every-command-fails-with-command-not-found-after-changing-bash-profile getting: env: bash: No such file or directory env: bash: No such file or directory env: bash: No such file or directory env: bash: No such file or directory env: bash: No such file or directory -bash: tar: command not found -bash: grep: command not found -bash: cat: command not found -bash: find: command not found -bash: dirname: command not found -bash: /preexec.sh.lib: No such file or directory -bash: preexec_install: command not found -bash: sed: command not found -bash: git: command not found My bash_profile actually pulls in other .sh files (sources them) so I am not exactly sure which modification may have caused this. Now if I even try and to a list of files, I get: >ls -bash: ls: command not found -bash: sed: command not found -bash: git: command not found Any tips on how to trace the source of the error, and how to be able to use the terminal for basic things like listing files etc? command-line bash share|improve this question edited Sep 13 '12 at 14:13 Jjed 9,
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the http://stackoverflow.com/questions/5642521/command-not-found-error-in-bash-script company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions http://linuxcommand.org/wss0150.php Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up command not found error in bash script up vote 3 down vote favorite I have written a bash script. It command not basicaly gets three paths based on input parameters and then then gets the imagename/filename in the path. Something like: I provide: AA=/home/user Then it uses the find command to get /home/user/dir2/images/dir/tellmeimage1fun.bin Finally I have to get tellmeimage1fun.bin as output. Script: #!/bin/bash echo "arg0 n/k/d" AA=$1 CC=$3 PATH1="`find $AA/dir2/images/dir/ -name *image1*.bin`" PATH2="`find $AA/dir2/images/dir/ -name *bimage2*.bin`" PATH3="`find $AA/dir2/images/dir/ -name *cimage3*.bin`" if [ $CC = "n" ] ; then PATH=$PATH1 elif [ $CC = "k" ] command not found ; then PATH=$PATH2 else PATH=$PATH3 fi #Getting filename name from path: IMG="`ls $PATH | cut -d "/" -f6`" OUTPUT: /users/prasapat/bin/sl5: line 22: ls: command not found /users/prasapat/bin/sl5: line 22: cut: command not found If I give complete paths to ls and cut they work. But i dont want to do that for all commands in the script. If i remove the last line and echo the PATH variable it is completely fine. Only after adding the last command, I see the probelm. Kindly help and let me know if I have done any obvious error. bash share|improve this question edited Apr 12 '11 at 22:54 John Flatness 19.2k25468 asked Apr 12 '11 at 22:48 Pkp 33941226 add a comment| 5 Answers 5 active oldest votes up vote 7 down vote accepted The problem is that you are redefining the PATH variable where bash looks into to find the binary files if you don't use a complete path when calling. You should change the PATH in your bash script to MYPATH or something like that, so that it doesn't mess with the already environmental variables. If you don't know what the PATH variable is for you can look at wikipedia's article share|improve this answer answered Apr 12 '11 at 22:56 SanSS 3,7881434 Thanks a lot! Such a
and Signals and Traps (Oh My!) - Part 1 by William Shotts, Jr. In this lesson, we're going to look at handling errors during the execution of your scripts. The difference between a good program and a poor one is often measured in terms of the program's robustness. That is, the program's ability to handle situations in which something goes wrong. Exit status As you recall from previous lessons, every well-written program returns an exit status when it finishes. If a program finishes successfully, the exit status will be zero. If the exit status is anything other than zero, then the program failed in some way. It is very important to check the exit status of programs you call in your scripts. It is also important that your scripts return a meaningful exit status when they finish. I once had a Unix system administrator who wrote a script for a production system containing the following 2 lines of code: # Example of a really bad idea cd $some_directory rm * Why is this such a bad way of doing it? It's not, if nothing goes wrong. The two lines change the working directory to the name contained in $some_directory and delete the files in that directory. That's the intended behavior. But what happens if the directory named in $some_directory doesn't exist? In that case, the cd command will fail and the script executes the rm command on the current working directory. Not the intended behavior! By the way, my hapless system administrator's script suffered this very failure and it destroyed a large portion of an important production system. Don't let this happen to you! The problem with the script was that it did not check the exit status of the cd command before proceeding with the rm command. Checking the exit status There are several ways you can get and respond to the exit status of a program. First, you can examine the contents of the $? environment variable. $? will contain the exit status of the last command executed. You can see this work with the following: [me] $ true; echo $? 0 [me] $ false; echo $? 1 The true and false commands are programs that do nothing except return an exit status of zero and one, respectively. Using them, we can see how the $? environment variable contains the exit status of the previous program. So to check the exit status, we could write the script this way: # Check the exit status cd $some_directory if [ "$?" = "0" ]; then rm * else echo "Cannot change directory!" 1>&2 exit 1 fi In this version, we examine the exit status of the cd command and if it's not zero, we print an error message on standard error and terminate the script with an exit status of 1. W