Not Found Shell Script Error
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 sh file not found this site About Us Learn more about Stack Overflow the company Business Learn sh command not found linux more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question what is found in a shell _ Unix & Linux Stack Exchange is 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
Command Not Found Shell Script Variable
how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Shell script throws a not found error when run from a sh file. But if entered manually the commands work up vote 8 down vote favorite 3 I'm trying to use the following script to generate a sitemap for my website. When I shell found on beach run it as sh thsitemap.sh I get an error like this and creates an empty sitemap.xml file: thsitemap.sh: 22: thsitemap.sh: [[: not found thsitemap.sh: 42: thsitemap.sh: [[: not found thsitemap.sh: 50: thsitemap.sh: Syntax error: "(" unexpected But as the same user root when I manually copy and paste these lines on the terminal, it works without any error and the sitemap.xml file have all the urls. What's the problem? How can I fix this? #!/bin/bash ############################################## # modified version of original http://media-glass.es/ghost-sitemaps/ # for ghost.centminmod.com # http://ghost.centminmod.com/ghost-sitemap-generator/ ############################################## url="techhamlet.com" webroot='/home/leafh8kfns/techhamlet.com' path="${webroot}/sitemap.xml" user='leafh8kfns' # web server user group='leafh8kfns' # web server group debug='n' # disable debug mode with debug='n' ############################################## date=`date +'%FT%k:%M:%S+00:00'` freq="daily" prio="0.5" reject='.rss, .gif, .png, .jpg, .css, .js, .txt, .ico, .eot, .woff, .ttf, .svg, .txt' ############################################## # create sitemap.xml file if it doesn't exist and give it same permissions # as nginx server user/group if [[ ! -f "$path" ]]; then touch $path chown ${user}:${group} $path fi # check for robots.txt defined Sitemap directive # if doesn't exist add one # https://support.google.com/webmasters/answer/183669 if [ -f "${webroot}/robots.txt" ]; then SITEMAPCHECK=$(grep 'Sitemap:' ${webroot}/robots.txt) if [ -z "$SITEMAPCHECK" ]; then echo "Sitemap: http://${url}/sitemap.xml" >> ${webroot
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 company Business Learn more about hiring no such file or directory in unix shell script developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Things Found In Shells
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join
Not Found No Such File Or Directory In Shell Script
them; it only takes a minute: Sign up command not found error message after I try to run a UNIX script up vote 8 down vote favorite I'm learning how to make shell scripts in UNIX, but I keep coming http://unix.stackexchange.com/questions/155838/shell-script-throws-a-not-found-error-when-run-from-a-sh-file-but-if-entered-ma across this stupid error. Let's say I make a script like this: #!/bin/sh echo HELLO I save the file as test, and make the command executable by me with chmod 700 test. I save the file in my home directory, and (attempt) to run the file like so: ./test Only for UNIX to reply back: ./test: Command not found. What is going on? When I type out ls -l, there is an asterisk next to the file name. That http://stackoverflow.com/questions/3866978/command-not-found-error-message-after-i-try-to-run-a-unix-script wasn't there before I used the chmod command. Can anyone tell me what I'm doing wrong? unix shell share|improve this question edited Oct 5 '10 at 22:34 Jonathan Leffler 441k62512824 asked Oct 5 '10 at 19:26 Waffles 41113 2 Does ls /bin/sh show a file with the executable bit enabled? –Ether Oct 5 '10 at 19:58 When you add the missing slash, do you still run into the problem? Is the directory you are in mounted with any (very) peculiar options? –Jonathan Leffler Oct 5 '10 at 22:36 add a comment| 10 Answers 10 active oldest votes up vote 7 down vote Make it executable: chmod +x ./test and make sure you save your file in unix file format. And: check if your partition is executable (mount) share|improve this answer edited May 29 '13 at 13:34 answered Oct 5 '10 at 19:33 ivy 4,70412340 add a comment| up vote 5 down vote It looks like you need a slash before the bin: #!/bin/sh # ^ Everything else looks fine... I'm assuming that /bin/sh is the location of your executable Bournse shell - if it is not, you would need to adjust as appropriate. Without the leading slash your shell is looking for bin/sh relative to your current directory, rather than where it truly resides. You'll need to locate the executable shell interpreter that you want (or need) for your scripts. A
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 company http://superuser.com/questions/703384/bash-script-gives-command-not-found-error-on-if-elif-statements Business Learn more about hiring developers or posting ads with us Super User Questions Tags Users Badges Unanswered Ask Question _ Super User is a question and answer site for computer enthusiasts and power users. Join them; http://www.cyberciti.biz/faq/linux-unix-command-not-found-error-and-how-to-get-rid-of-it/ it only takes a minute: 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 Bash script gives “command not found” error not found on if elif statements up vote 4 down vote favorite Now before you flag this as a duplicate please understand i did search for this problem and i already tried all of the solutions to no effect. My script: #!/bin/bash echo "Enter the number 3" read t1 if [$t1 -eq 3]; then echo "it is 3" elif [$t1 > 3]; then echo "it is greater than 3" fi exit 0 The error i get is: not found shell ./g.sh: line 5: [3: command not found ./g.sh: line 7: [3: command not found linux bash shell-script share|improve this question asked Jan 18 '14 at 3:05 Skilo Skilo 2826 add a comment| 1 Answer 1 active oldest votes up vote 8 down vote accepted spaces needed if [ $t1 -eq 3 ] share|improve this answer answered Jan 18 '14 at 3:08 Fivesheep 25614 you gotta be kidding me... Bash is one picky SOB. –Skilo Skilo Jan 18 '14 at 3:11 4 @SkiloSkilo it's not bash - [ is its own executable. It lives in /bin on my Mac, may be elsewhere in Linux. Program names always need spaces around them. –MattDMo Jan 18 '14 at 4:08 In this case [ is fine, however if your variable isn't in quotes or you want pattern matching, then use [[ ibm.com/developerworks/opensource/library/l-bash-test/… –spuder Jan 18 '14 at 5:09 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged linux bash shell-script or ask your ow
am getting the error Command not found? How do I fix this problem?A common question asked by new Linux or UNIX users. When you get the error "Command not found" it means that Linux or UNIX searched for command everywhere it knew to look and could not find a program by that name. Another cause is you misspelled the command name (typo) or administrator does not at all install the command on your Linux/UNIX based system. To get rid of this error try the following suggestions:
Make sure command was not misspelledAll Linux and UNIX commands are case sensitive and you need to type correct spelling of command.Make sure command is your pathYou can see current search path with following command:$ echo $PATHSample outputs:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/home/vivekgite/binUsually, all user commands are in /bin and /usr/bin or /usr/local/bin directories. All your programs are installed in these directories. When you type the clear command, you are running /usr/bin/clear. So if it is not in your path try to add directories to your search path as follows (setup Linux or UNIX search path with following bash export command):$ export PATH=$PATH:/bin:/usr/local/binYou can also find out of path of any command with which or whereis commands:$ which ls/bin/ls$ which gcc/usr/bin/gcc$ which date/bin/date$ which cal/usr/bin/cal$ whereis gcc/usr/bin/gccYou can run a program using its full pathname as follows:$ /bin/ls $ /bin/dateFinally, sometime you may not have permission to run the command.ExampleLet's assume the program you want to execute is called "cal" and you get a "Command not found" message from Unix or Linux. First, type the following command to see if you get a path name:$ whereis calSample outputs:cal: /usr/bin/cal /usr/share/man/man1/cal.1.gzIf you do, you can invoke it using a full path name (e.g. /usr/bin/cal):$ /usr/bin/calSample outputs: September 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Or You can add the path to your PATH variable in your shell start-up file $HOME/.cshrc (csh/tcsh) or $HOME/.bashrc (bash) file, then "source" the file:$ vi $HOME/.bashrcAdd the path as follows: PATH=$PATH:/home/vivek/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games export PATH Save and close the file. Run the following command:$ source ~/.bashrc$ echo $PATH
$ calFinally, you can use the following command to search for cal command get a hit about its location.$ find / -name cal -printThen, invoke