Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Naming Shell Scripts

Status
Not open for further replies.

barryp

Programmer
Jan 30, 2002
48
GB
Basic Question:

Shell script called 'test' with execute permission which contains one line

echo "hello"

>sh test - I get hello
>test - I see nothing

Rename test to @test

>sh @test - I get hello
>@test - I get hello

Can someone explain this please ?
 
In Unix-like operating systems, if you want to execute a script as as command, the script must contain a shebang line which tells the system through which scripting engine the script should be run.

For example, a simple bash script might read:
Code:
#!/bin/bash

echo "Hello, world!"

The line which reads "#!/usr/bin/bash" is the shebang line and "#!" is a shebang. This particular shebang line tells the OS that this script must be run through the command parser /bin/bash (or in other words, this is a bash script). The shebang line must be the first line of your script.


It's not like DOS, where you don't have a choice of scripting engines -- all DOS has is command.com. *nix OSes have a lot of engines available: perl, bash, zsh, ruby, etc.


______________________________________________________________________
TANSTAAFL!
 
test is a standard unix command and it is this that runs instead of your script.

running 'sh test' works because the sh program will only look in the current dir. when you create a script you should run it with './test'

if you run 'echo $PATH' you will see where the shell will look for programs first. one of these will be /usr/bin where the real test is kept.
 
Thanks for the input

Bad choice of name 'test' - using 'mytest' now

Without a shebang it seems to work - probably defaults to 'sh'

What does the '@' do as in

>@mytest

as opposed to

>mytest
 
i don't know why the @ works for you, it doesn't for me. i'm using bash where using an @ lets you autocomplete on hostnames eg.

telnet @localhost
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top