Visit Our UNIX and Linux User Community


Need to execute the script with script name wihtout using ./scriptname in Solaris 10


 
Thread Tools Search this Thread
Operating Systems Solaris Need to execute the script with script name wihtout using ./scriptname in Solaris 10
# 1  
Old 05-08-2013
Sun Need to execute the script with script name wihtout using ./scriptname in Solaris 10

Hi,
I am using solaris 10.Is there any way to execute the script with the scriptname wihtoug using ./scriptname?Also does it varies from shell to shell.I have scripts in bash,ksh,sh shells.


Example:script.sh is the script name.I need to execute the script like this script.sh instead of ./script.sh.Does it varies from shell to shell?

Advance thanks for your reply.
# 2  
Old 05-08-2013
make the file script.sh executable by changing its file permissions.
Use following command for this.
Code:
chmod 777 script.sh

Then you can execute it by
Code:
sh script.sh

# 3  
Old 05-08-2013
Some use full info for you to take a decision

Quote:
The '.' refers to the current directory. The '/' is either a directory separator or a way to ensure we are referring to a directory and not a file.

By itself, './' and '.' will do the same thing, since the current directory is always a directory. So 'ls .' and 'ls ./' will do the same thing.

However, if you want to refer to the file 'foo' in the current directory, you need the '/' as a directory separator. So you would use './foo'.

The reason you need to put a './' on the beginning to run a program from the current directory is for security. If I could create a program called 'ls' and get you to 'cd' to my directory and type 'ls', I could get you to run a malicious program.

So if you want to run a program from the current directory, most shells by default force you to indicate so specifically. You can override this by added '.' to the list of directories tested for executables (the 'PATH' environment variable) but that's probably not a good idea.
# 4  
Old 05-08-2013
You have several choices:

- Use an absolute path like /home/mydir/script.sh command.

- Put the script in a directory that is part of your PATH, which you can check with echo $PATH and set in your $HOME/.profile config file. You could have a $HOME/bin directory and put your scripts there, and include it in your PATH.

- It's possible the "current directory" is in your path (not the safest thing), in which case you can just execute the command by typing "script.sh" if you are in the same directory as the script.
# 5  
Old 05-08-2013
Quote:
Originally Posted by Nakul_sh
make the file script.sh executable by changing its file permissions.
Use following command for this.
Code:
chmod 777 script.sh

Then you can execute it by
Code:
sh script.sh

The first step (making the script executable) is actually not required when you use that method (sh file) to launch the script. Moreover, chmod 777 pose a security risk, use chmod +x instead.

Previous Thread | Next Thread
Test Your Knowledge in Computers #75
Difficulty: Easy
Apple's Mac OS X was based on NeXTStep, but iOS was not based on Mac OS X.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Should I run scripts like sh /absolute_path/to/scriptname.sh or just /absolute_path/to/scriptname.sh

Shell : Linux Bash OS version : RHEL 6.X, Oracle Linux 6.X Question1. To execute shell scripts, sometimes I see Linux admins placing sh command before shell scripts like below sh /home/appadmin/sync_pending_orders.shBut, I execute shell scripts like below ie. Just the absolute path ... (4 Replies)
Discussion started by: John K
4 Replies

2. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

3. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

4. Solaris

write a script to execute some operations on sun solaris

Sun Microsystems Inc. SunOS 5.9 Generic May 2002 SUNFIRE V240 if there is a power failure, automatically: write all operations in a log file (0 Replies)
Discussion started by: doudou2012
0 Replies

5. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

6. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

7. Windows & DOS: Issues & Discussions

Windows remote to Solaris to execute ksh script

Hi all, I'm not sure if it is correct to post here. I am facing problem wanting to create a batch that run from my Windows XP pc to remote to multiple Solaris server to execute the server's ksh script. :wall: Can anyone give me a hints on how to do that? Thanks. (6 Replies)
Discussion started by: beginningDBA
6 Replies

8. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

9. UNIX for Dummies Questions & Answers

run script without ./scriptname

Hi everyone, I'm very new, I just wrote a script "Hello World" :) LOL How can I execute the script without the ./myscript. I want to just type "myscript" basically from anywhere without the " ./ ". Thanks a bunch, NinjaX (2 Replies)
Discussion started by: NinjaXman
2 Replies

10. UNIX for Dummies Questions & Answers

Can Unix (Solaris) execute a dos .bat script?

I did a search and found lots of questions/comments about how a dos script could execute Unix but not the other way round. If it's possible, I'd like the link to a post/site that would show me the way. Thanks. (4 Replies)
Discussion started by: BCarlson
4 Replies

Featured Tech Videos