Starting script without ./ name or sh name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Starting script without ./ name or sh name
# 1  
Old 12-11-2008
Starting script without ./ name or sh name

Hi, i want to start my script only by the name of it.



$ scriptName


normaly i have to use ./scriptName oder sh scriptName

is there a way to do that in bash or sh ?
# 2  
Old 12-11-2008
Hi,

Try this:
1. Type a command called as "pwd" on your terminal(where you have written your program), copy the result.

2. Now type the command "setenv PATH (result of pwd command, excluding the() braces):{$PATH}

This should work.

eg:1. pwd
/home/vishwa/programs

2. setenv PATH /home/vishwa/programs:{$PATH}
# 3  
Old 12-11-2008
well the setenv command is not found but thats not the problem i think,

you want to add the path of the script to the path of the system variables so i can reach the script in any directory, but thats not the problem i have

i have the script in the same directory where i want to open it, i wanted to know if there is a way without changing some system variables to open it by name so i can call it on an other host where i have copyed it too.

is there a way ?
# 4  
Old 12-11-2008
You place it in the /usr/bin folder, I think.

Edit: Ok, not quite.. I think that just allows you to type scriptName.sh in any directory

Edit again: Aha, got it. Add #!/bin/bash to the top of your script file, remove the .sh extension, and then put it in your /usr/bin folder. You will need to use sudo mv to move it, and sudo chmod +x to execute it.

$ scriptName will then execute /usr/bin/scriptName, interpreting the commands with the bash library.

Last edited by baza210; 12-11-2008 at 09:43 AM..
# 5  
Old 12-11-2008
I already did that but
$ scriptName
bash : criptName : command not found

$cat Script

#!/usr/bin/bash

echo "test"


ls -l scriptName

-rwx-r-xr-x


with ./scriptName it works
or sh scriptName

OS : Debian Lenny
Alternativ : cygwin

on both the same "problem"
# 6  
Old 12-11-2008
In OS X:

brian-1000h:~ admin$ sudo nano /etc/bin/test1
Password:

-----Nano-----
#!/bin/bash
echo "omgwtfhax"

Ctrl+x , y, Enter

brian-1000h:~ admin$ sudo chmod +x /usr/bin/test1
brian-1000h:~ admin$ test1
omgwtfhax


Dunno what the difference is there, other than I have #!/bin/bash at the top of mine, and you have #!/usr/bin/bash.. maybe it's not reading the library correctly because of the /usr/ bit. That would explain why you have to tell it that it's a bash file.
# 7  
Old 12-11-2008
The setenv command is a csh thing.

To add a directory to your PATH in bash:
export PATH=${PATH}:/path/to/directory

Add this to your local profile or /etc/profile. You could also copy the script to any directory already defined in your current path:

echo $PATH
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

2. Shell Programming and Scripting

Script for Starting Firefox?

Presently I have a powershell script (windows only, of course) that enumerates all the instances of "Internet Explorer" running on my machine and if at least one exists, the script creates a new tab in that instance with the URL I have provided. If no instances of Internet Explorer are running, one... (1 Reply)
Discussion started by: siegfried
1 Replies

3. Shell Programming and Scripting

Starting all the components simultaneously through script

Hi Folks , I have the below script that will start the components one by one by giving an interval of few seconds that if first component is started then there is interval of few seconds and then the second component is started , but by this way it takes time, i want to make the process faster... (8 Replies)
Discussion started by: punpun66
8 Replies

4. Shell Programming and Scripting

Help with Temperature Script (Starting

Hello, I am trying to work on a temperature script to check temperatures on my systems. Im trying to get the basics laid out first. So far i have a command: /usr/sbin/prtpicl -v -c temperature-sensor # (must run as root) This command kicks back alot of information but i only want the... (3 Replies)
Discussion started by: whotippedmycow
3 Replies

5. Shell Programming and Scripting

Help starting a script

Hi guys, i already search in this forum and i can't find a way to do this. I have a file like this: -1 1 lig -1 1 lig -1 1 lig -1 -1 dec -1 -1 dec -1 -1 dec -1 -1 dec -1 -1 dec -1 -1 dec And i need to compare the values of... (7 Replies)
Discussion started by: MetaBolic0
7 Replies

6. Shell Programming and Scripting

Starting a C++ program from shell script

Hi, I have a little problem...I want to do the following things: Have my own little script that has 2/3 functions and starts a c++ application using some parameters. The problems appear when I start the c++ app using the shell script, the c++ takes over and after I ctrl+c the script... (0 Replies)
Discussion started by: valiadi
0 Replies

7. Shell Programming and Scripting

Manage starting point in shell script.

Hi, I'd like to run a script with an optional starting point. Meaning that if no parameter for the script => Do everything, otherwise start from the point specified in the parameter and continue till the end. I thought of using the "case ..." but I have no result. Script: # ---------------... (6 Replies)
Discussion started by: ai_dba
6 Replies

8. UNIX for Dummies Questions & Answers

Problem starting a script from a 'main'-script

Please Help! :o I have a main script (ksh) where another script is called (convert_picture). Normally this works ok, but since some changes has been made on the unix-server (I dont know what :( ) suddenly it doesnt work anymore: i get an error message: ksh: convert_picture not found. I am... (3 Replies)
Discussion started by: Rakker
3 Replies

9. Shell Programming and Scripting

Help starting a simple shell script.

I've been sitting here for 6 hours typing out all kinds of different ridiculous(very pointless) shell scripts for a low-level UNIX class. I'm tired.. and want to go to bed :o Can somebody please help get me on the right path to starting this damn script? i'm useless after all these hours and... (2 Replies)
Discussion started by: dickmartin
2 Replies

10. UNIX for Advanced & Expert Users

Starting a script from a Database procedure

Hey guys, I have this problem : I can run on an sqlprompt !ftp_file2.ksh test.xml 172.16.204.81 Anonymous Anonymous which will ftp the file from Unix to an NT machine, but if I do exec shell('sh ftp_file2.ksh test.xml 172.16.204.81 Anonymous Anonymous') it does NOTHING. I have no... (4 Replies)
Discussion started by: vidireporting
4 Replies
Login or Register to Ask a Question