LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2005, 05:49 PM   #1
osio
Member
 
Registered: Jun 2005
Posts: 70

Rep: Reputation: 15
make a bash script accesible from anywhere in the system


I have written a number of scripts, basically to recursively manipulate files and images in directories. I have to copy the scripts into the pwd to run them, which becomes burdensome.
How can I export the path to a bash script so wherever I am in the system I can do
$ sh myscript.sh
without myscript.sh being in the precise pwd of the moment?
Thanks!
 
Old 09-19-2005, 06:02 PM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
I would recommend to copy them in /usr/local/bin
 
Old 09-19-2005, 06:13 PM   #3
osio
Member
 
Registered: Jun 2005
Posts: 70

Original Poster
Rep: Reputation: 15
shell script at /usr/local/bin

Thnx, but I bumped into this problem.
One script is a csh one.
When I place it at /usr/local/bin and do
$ csh myscript.sh
myscript: No such file or directory
$ sh myscript.sh
returns syntax errors (my default shell is a bash one).
 
Old 09-19-2005, 06:32 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Can you explain better:
- how do you fail to export your path to subshells ?
- why do you need to launch your script with "sh script" instead of "script" ?
 
Old 09-19-2005, 06:35 PM   #5
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Code:
$ csh myscript.sh
myscript: No such file or directory
that does not make sense.
It should be:
Code:
$ csh myscript.sh
myscript.sh: No such file or directory
also consider putting #!/bin/csh as the first line in the script and give execute permission to the script
and run it as
Code:
myscript.sh
 
Old 09-19-2005, 06:39 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Giving .sh as an extension for a csh script doesn't make sense either.

Even writing a csh script doesn't make sense nowadays.
 
Old 09-19-2005, 06:42 PM   #7
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Quote:
Originally posted by jlliagre
Even writing a csh script doesn't make sense nowadays.
THATS SO TRUE..........
 
Old 09-19-2005, 07:29 PM   #8
osio
Member
 
Registered: Jun 2005
Posts: 70

Original Poster
Rep: Reputation: 15
Smile done

well, I had rewritten the script in bash by the time at looked back at the post.

Thnx.
 
Old 09-20-2005, 12:39 PM   #9
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 25, 26, RHL 5.2
Posts: 560

Rep: Reputation: 56
I would go with perfect-circle's advice of putting the she-bang (#!/bin/...) line at the beginning of each script. That way you don't have to figure out what shell goes with which script. It is both self documenting and self running.

To execute a script from anywhere on your system it needs to be in your $PATH environment variable. It is common to place scripts that anyone can execute in /usr/local/bin. If you are a user and want to execute scripts that you wrote, place them in your own bin and make sure this gets into your $PATH. For example if your user name is scooby then put your scripts in /home/scooby/bin.

Bill
 
Old 09-20-2005, 02:33 PM   #10
osio
Member
 
Registered: Jun 2005
Posts: 70

Original Poster
Rep: Reputation: 15
points taken

All right, I understand.
Thank you!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script - How do I make sure my program is still running? nro Linux - Newbie 4 08-28-2005 01:57 PM
Does anyone know of a bash script that will determine if RPM exists on a system? jimwelc Linux - Software 3 12-28-2004 03:01 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration