Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
my script goes sth like this:
script1.sh
#!/bin/bash
source ./script2.sh
my folder structure looks like this:
folder1/script1.sh
/script2.sh
i am executing like this:
Code:
$./script1.sh
it gives me:
script1.sh: line x: script2.sh: No such file or directory
the problem is not the script or syntax, because if i create a new file in folder1, say script1-1.sh, and copy paste the content of script1.sh to it, it executes just fine. i suspect bash or my shell emulator to be the culprit here.
while writing this i just realized that my problem is easily solved with a copy paste, but i'd rather want to know what is going on here and fix it.
my terminal is xfce4-terminal 0.6.3, bash version is 4.3.11(1) on linux mint xfce x86, the system is practically fresh save for some changes in the firefox configuration and changing the opacity of said shell emulator.
the system is up for some time now, though, about a week with some supends in between.
any help or pointers appreciated, thanks a lot!
EDIT: btw, since the system is practically fresh not much was done or saved on it, if someone is curious she or he could have a look at it through teamwiewer or ssh or whatever, i am not that much of an expert there.
Last edited by chatumao; 03-07-2017 at 03:00 PM.
Reason: format
Are you in folder1 when you run this script? Or is folder1 in your PATH variable?
The directory where script2.sh is located is important. Remember that ./script2.sh means to run that from the current working directory. Therefore if you are not in the directory where script2.sh is located, you will see exactly the complaint you are seeing.
Another thing to consider is to add
Code:
set -xv
after the #!/bin/bash line in your script to enable extra debugging. And then later comment that out using # at the start of the line so as to keep it there for future reference. The extra debug should inform you how it is attempting to run the script2.sh.
Please remember to use [code][/code] tags to enclose your code.
my script goes sth like this:
script1.sh
#!/bin/bash
source ./script2.sh
my folder structure looks like this:
folder1/script1.sh
/script2.sh
i am executing like this:
Code:
$./script1.sh
it gives me:
script1.sh: line x: script2.sh: No such file or directory
From the directory layout you posted, script2.sh is in the parent of script1.sh? Is that correct? Or did LQ just lose the formatting? (BTW use code tags in the future for this).
If they're in the same directory, why are you even qualifying the directory to script2?
Code:
source script2.sh
should be enough if they are in the same directory.
i made sure my cwd is set correctly, which it was, and also activated the debugging options. unfortunately no luck with that. these only give me two additional lines after i execute
Code:
./script1.sh
+ ./script1.sh
which does not tell me anything tbh.
just for the hell of it i added
Code:
echo hello
before
Code:
source ./script2.sh
and after executing i still get the exact same output as before. it is as if bash or the emulator had some sort of cache and an old version of my script is being executed. i am no linux guru and such knowledge is beyond me, that's why i ask here. the only other explanation i could come up with would be faulty ram. but i don't believe it's that, and i cannot reboot my system atm anyways since i am in the progress of some stuff...
i made sure my cwd is set correctly, which it was, and also activated the debugging options. unfortunately no luck with that. these only give me two additional lines after i execute
Code:
./script1.sh
+ ./script1.sh
which does not tell me anything tbh.
just for the hell of it i added
Code:
echo hello
before
Code:
source ./script2.sh
and after executing i still get the exact same output as before. it is as if bash or the emulator had some sort of cache and an old version of my script is being executed. i am no linux guru and such knowledge is beyond me, that's why i ask here. the only other explanation i could come up with would be faulty ram. but i don't believe it's that, and i cannot reboot my system atm anyways since i am in the progress of some stuff...
Ok, shot in the dark, what happens if source do
Code:
source script2.sh
at a shell prompt?
I'm wondering if there is something in script2 itself causing this.
Of course, I'm thinking we're not seeing the actual scripts, and so we can't fully diagnose the problem.
yeah, lq seems to have lost the formatting there. structure should be like this
Code:
folder1/script1.sh
script2.sh
meaning both scripts are in the same folder.
but as i posted before, that is not the problem at all. the script is simply not executed as it is, bash is executing an old version of it.
i closed the shell and opened another one, same error. i typed
Code:
bash
and tried it there, same thing. not sure, but i think this eliminated bash as the culprit?
any other terminals i could try on linux mint?
ok, i solved it. sorry to have bothered you, i had two copies of script1.sh open and did not realize i changed the one i did not execute. that was pretty useless now, very sry to have wasted your time . but thanks anyways, i'm back on track now.
ok, i solved it. sorry to have bothered you, i had two copies of script1.sh open and did not realize i changed the one i did not execute. that was pretty useless now, very sry to have wasted your time . but thanks anyways, i'm back on track now.
Glad you solved it.
I hate that "sorry to bother you" thing I've been seeing. That's what we're here for, is to help, if we can.
And don't worry... I just went through the same thing last night with a python script I was working on.
yeah, sometimes its the most obvious things that seem unsolvable... i guess i forgot that 99 out of 100 cases the problem is in front of the screen, not behind it
anyways, thanks for the help!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.