Running scripts in bash

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Running scripts in bash
# 1  
Old 03-19-2018
Running scripts in bash

So I've written my first bash script.I wanted to run it from the command line, but I got an error:
Code:
$ myscript.sh
myscript.sh: command not found

So instead I try this and it works:
Code:
$  ./myscript.sh

Is this how I will always need to execute it? How can I run myscript.sh without having to precede it with ./?
# 2  
Old 03-19-2018
Welcome to the forum. And thanks for using codes tags correctly from the beginning.

bash looks for executables in the directories listed in the PATH shell variable, to which the working directoy . usually is not (and should not be) added for security reasons. One workaround would be to add a certain path, e.g. ~/bin, and collect all your scripts there. But you would need to keep tight control of the scripts and versions in there to avoid adding (and executing) malicious code to / from there.
# 3  
Old 03-20-2018
Thank you so much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running scripts in background

Hi, below is my master script wihch inturn runs 2 scripts in background #master_script.sh ./subscript1.sh & ./subscript2.sh & executed the master_script.sh from unix command prompt $ ./master_script.sh it is executing the subscripts and they are completing fine, however master_script.sh is... (2 Replies)
Discussion started by: JSKOBS
2 Replies

2. Shell Programming and Scripting

[BASH] Script to manage background scripts (running, finished, exit code)

Heyas, Since this question (similar) occur every now and then, and given the fact i was thinking about it just recently (1-2 weeks) anyway, i started to write something :p The last point for motivation was... (17 Replies)
Discussion started by: sea
17 Replies

3. UNIX for Dummies Questions & Answers

Running scripts from different server

Hi, I need a script (ksh) on ServerAdmin that will run an archive scripts from different several Servers through ssh. The problem is that how can i switch user when before running the archive script. I already configured password-less connection on the servers. server 1... (1 Reply)
Discussion started by: chococrunch6
1 Replies

4. UNIX for Dummies Questions & Answers

Running CSh scripts in Bash

Hi, I have some csh scripts and I want to run them in .bashrc. I use these techniques without any success: . test.csh or csh test.csh The first one assumed that the scripts is a bash script, so showed me errors. The second one finished without giving proper result. Can anybody offer... (6 Replies)
Discussion started by: mjdousti
6 Replies

5. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

6. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

7. Shell Programming and Scripting

sequential running for 2 scripts

Hello I have a script that has 2 scripts that must be executed one after the other. however, when I run the script, the 2 sub-scripts are run in parallel. any idea how to fix this without using sleep command? thank you (7 Replies)
Discussion started by: melanie_pfefer
7 Replies

8. Shell Programming and Scripting

Running scripts via su

Hi All, Am using the below command to start my application using the root user su - bin -c "/home/bin/test/start.sh" but am getting the error becaue i have set some environment varibales in bin .profile when i execute the command start.sh by logging directly into bin account it's... (8 Replies)
Discussion started by: ravi.sri24
8 Replies

9. UNIX for Dummies Questions & Answers

Automatically Running Scripts

Can someone advise me how to get started automatically running scripts? I believe it has something to do with cron? (4 Replies)
Discussion started by: jeffreydavisjr
4 Replies

10. Shell Programming and Scripting

Running scripts unattended

Hi guys just wondering how i could make one of my scripts run unattended without the use of cron? (3 Replies)
Discussion started by: musicmancanora
3 Replies
Login or Register to Ask a Question