chantown Posted September 9, 2007 Share Posted September 9, 2007 Hi, Does anyone know why this is happening? I have a script: #!/bin/bash echo wonderful Saved as go, CHMOD to executable i run the script in root: bash go And this is what is says: wonderful : command not found : command not found Now, I know it's finding "bash" or whatever that is...i did "which bash" in my command line, and it said /bin/bash And bash reallly is there~! So what is going on!? thanks~ Quote Link to comment Share on other sites More sharing options...
neylitalo Posted September 9, 2007 Share Posted September 9, 2007 Without quotes, it tries to execute the program called 'wonderful', which probably isn't going to be found. If you want to echo the string "wonderful", do this: #!/bin/bash echo "wonderful" And in the future, enclose scripts, program output, etc., in tags. Quote Link to comment Share on other sites More sharing options...
chantown Posted September 9, 2007 Author Share Posted September 9, 2007 thanks neylitalo, but that still doesn't work wonderful : command not found : command not found I tried to google it, and they said i need to "find the bash" or something? Quote Link to comment Share on other sites More sharing options...
neylitalo Posted September 9, 2007 Share Posted September 9, 2007 Give us the complete contents of your script. Quote Link to comment Share on other sites More sharing options...
chantown Posted September 9, 2007 Author Share Posted September 9, 2007 oh ok I created script named "go" #!/bin/bash echo "wonderful" Uploaded to root, made executable (777) login as root, typed bash go And this is what is returned: wonderful : command not found : command not found typed "which bash" , and it returns "/bin/bash" thxxx Quote Link to comment Share on other sites More sharing options...
neylitalo Posted September 9, 2007 Share Posted September 9, 2007 One of two things has happened: You're not using the right file, or you're not uploading the right file. Make sure that you're editing the right file, saving it, uploading it to the server (if you're indeed uploading the file), and then running the right file. Quote Link to comment Share on other sites More sharing options...
chantown Posted September 9, 2007 Author Share Posted September 9, 2007 It's the right file because it reads the wonderful part. I also did the command "vi" to see , and it is :-\ Quote Link to comment Share on other sites More sharing options...
neylitalo Posted September 9, 2007 Share Posted September 9, 2007 Run these commands: $ echo "wonderful" Just in case, the dollar sign isn't to be included in the command. It simply marks the end of the bash prompt. If your output looks like this, then proceed: $ echo "wonderful" wonderful Create a file called "test", without the quotes: #!/bin/bash echo "wonderful" Run these commands: $ chmod +x test $ ./test And now see if you get the results you expected. Quote Link to comment Share on other sites More sharing options...
effigy Posted September 9, 2007 Share Posted September 9, 2007 Does this file have carriage returns in it? If so, you should see ^Ms in vi, and get an error if you try running ./go instead of bash go. Quote Link to comment Share on other sites More sharing options...
chantown Posted September 9, 2007 Author Share Posted September 9, 2007 Ok , I did those steps. When I enter the echo in the prompt, everything works as expected. It's the script that has the problem. If i run "./test", I get this: -bash: ./test: /bin/bash^M: bad interpreter: No such file or directory If i run "bash test", I get this: wonderful : command not found : command not found Quote Link to comment Share on other sites More sharing options...
effigy Posted September 9, 2007 Share Posted September 9, 2007 Use your editor to convert the file from DOS to Unix, or do the following in vi: Type :%s/, use the two key combinations Ctrl+V and Ctrl+M, type //g, and press Enter. Use :wq to save (write) and quit. Also, if you're learning how to use the shell, do not use the root account! Quote Link to comment Share on other sites More sharing options...
chantown Posted September 10, 2007 Author Share Posted September 10, 2007 why not? Can I create a user with the same permissions as root, and use that instead? Quote Link to comment Share on other sites More sharing options...
neylitalo Posted September 10, 2007 Share Posted September 10, 2007 why not? Can I create a user with the same permissions as root, and use that instead? No, for two reasons: 1) If you don't know what you're doing, you can destroy or disable your system very easily. It's very easy to make a typo and ruin your system even if you do know what you're doing. 2) If the active session were to be hijacked, either by technical or social engineering, you don't want the user logged in to be able to compromise the system. Your proposed "solution" would defeat the purpose, and I don't even think you can create a user with the same permissions as root. The root user has complete control over every single file, regardless of the permissions set on the file, and I'm fairly sure that's built into the Unix security system. When you need elevated privileges, you can use the "su" command to switch to the root account temporarily (on most distributions, you need to be in the 'wheel' group), or use sudo to execute a single command as a particular user. (By default, it executes commands as root.) One of the most basic rules of Unix administration: Never leave a root session open for any longer than necessary. Quote Link to comment Share on other sites More sharing options...
chantown Posted September 10, 2007 Author Share Posted September 10, 2007 wow, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.