Jump to content

Recommended Posts

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~

Link to comment
https://forums.phpfreaks.com/topic/68550-extreme-newbie-question/
Share on other sites

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.

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

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.

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.

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

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!

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.