954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to run/execute a script in a script?

Hello everyone.
Let's say i have 2 scripts called "fill_cup.sh" and "empty_cup.sh" and i create a 3rd script "cup.sh". How can i run/execute the scripts "fill_cup.sh" and "empty_cup.sh" in the script "cup.sh". I tried with sh fill_cup.sh and ./fill_cup.sh but it doesn't work.

for example

Script cup.sh

#!/bin/sh

echo enter a number

read rep

if test $rep eq 1
then
#execute the script "fill_cup.sh"
./fill_cup.sh #error: No such file or directory
done

if test $rep -eq 2
then
#execute script "empty_cup.sh"
./empty_cup.sh #error: No such file or directory
done


It gives me "No such file or directory" error
I gave the scripts all the permissions to read write and execute. I also made sure i'm present in the directory where the scripts are located and the run cup.sh but it still gives me the same error when it arrives to ./fill_cup.sh

mkab
Light Poster
29 posts since Feb 2011
Reputation Points: 10
Solved Threads: 2
 

Seemingly your pwd is not what you think it is.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

try this to seewhat is happening:

/bin/sh -x cup.sh
it will show you each line and result as it executes.

rch1231
Posting Shark
959 posts since Sep 2009
Reputation Points: 119
Solved Threads: 142
 
Seemingly your pwd is not what you think it is.


I thought about that but 200% sure that i'm in the right directory. pwd even shows that i'm in the right directory

edit: funnily it's working now. seems my pwd wasn't what i thought it was but i'm 100% sure that i'm was the right directory. By the way i'm using cygwin on windows and writing the code on wordpad. Don't know if that had any influence on the error.

Thanks all

mkab
Light Poster
29 posts since Feb 2011
Reputation Points: 10
Solved Threads: 2
 

Just a suggestion I used to work with cygwin I just switched to Putty and it works better! give it a try!

SakuraPink
Light Poster
31 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You