Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
03-07-2017, 03:18 PM
|
#1
|
LQ Newbie
Registered: Jul 2013
Posts: 7
Rep:
|
strange behavior in a bash script
hi there, i am having weird issues here.
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:
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 04:00 PM.
Reason: format
|
|
|
03-07-2017, 03:42 PM
|
#2
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,914
|
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 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.
|
|
|
03-07-2017, 04:08 PM
|
#3
|
Senior Member
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
|
Quote:
Originally Posted by chatumao
hi there, i am having weird issues here.
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:
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?
should be enough if they are in the same directory.
|
|
|
03-07-2017, 04:12 PM
|
#4
|
LQ Newbie
Registered: Jul 2013
Posts: 7
Original Poster
Rep:
|
still not working
first of all, thanks for your reply.
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 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...
|
|
|
03-07-2017, 04:20 PM
|
#5
|
Senior Member
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
|
Quote:
Originally Posted by chatumao
first of all, thanks for your reply.
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 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
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.
|
|
|
03-07-2017, 04:23 PM
|
#6
|
LQ Newbie
Registered: Jul 2013
Posts: 7
Original Poster
Rep:
|
some other tries
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 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?
|
|
|
03-07-2017, 04:36 PM
|
#7
|
LQ Newbie
Registered: Jul 2013
Posts: 7
Original Poster
Rep:
|
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.
|
|
|
03-07-2017, 05:20 PM
|
#8
|
Senior Member
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
|
Quote:
Originally Posted by chatumao
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.
|
|
|
03-07-2017, 05:35 PM
|
#9
|
LQ Newbie
Registered: Jul 2013
Posts: 7
Original Poster
Rep:
|
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!
|
|
|
All times are GMT -5. The time now is 09:22 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|