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
# 8  
Old 12-11-2008
Quote:
Originally Posted by baza210
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.
tryed /bin/bash also but didnt work


Quote:
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
with that it works, but i want to copy it on an other host and execute it without changing anything there, only with the scriptName.

Last edited by Turrican; 12-11-2008 at 11:23 AM..
# 9  
Old 12-11-2008
Quote:
Originally Posted by Turrican
i want to copy it on an other host and execute it without changing anything there, only with the scriptName.

To do what you want, the script has to be in a directory that is in the $PATH variable.

There is no other way.

# 10  
Old 12-12-2008
put current folder in path

PATH=.:$PATH

you can run all executable files in your current folder without giving ./ or sh.

but if a file in the current directory has the same name as another command , the script in your directory will override the other program.

e.g.
echo "clear" > ls
chmod u+x ./ls

now ls will act as clear... so it is kinda dangerous...

so remember to use which commandname if having doubts
# 11  
Old 12-12-2008
Quote:
Originally Posted by tarun
PATH=.:$PATH

you can run all executable files in your current folder without giving ./ or sh.

If you are going to put the current directory into your PATH (which is not recommended), don't put it first. Put it at the end:

Code:
PATH=$PATH:.

It is far better (i.e., safer) to create a directory for your scripts (e.g. $HOME/bin) and add that to your PATH.
# 12  
Old 12-12-2008
ok thx
# 13  
Old 12-12-2008
nice tip cfajohnson, thanks...

usually the default profile scripts on linux loook for the directory $HOME/bin and if it exists automatically add to the path...
so in case you have any of your own programs just put them in ~/bin and you can run them from anywhere..
# 14  
Old 12-12-2008
I created a new directory /local/bin and added it to the PATH and I put all my scripts in that directory so they are easy to find.

EDIT: I see cfajohnson had a similar response.. :P
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