LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 03-07-2017, 02:18 PM   #1
chatumao
LQ Newbie
 
Registered: Jul 2013
Posts: 7

Rep: Reputation: Disabled
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:
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
 
Old 03-07-2017, 02:42 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 03-07-2017, 03:08 PM   #3
goumba
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
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by chatumao View Post
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:
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.
 
Old 03-07-2017, 03:12 PM   #4
chatumao
LQ Newbie
 
Registered: Jul 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
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
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...
 
Old 03-07-2017, 03:20 PM   #5
goumba
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
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by chatumao View Post
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
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.
 
Old 03-07-2017, 03:23 PM   #6
chatumao
LQ Newbie
 
Registered: Jul 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
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
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?
 
Old 03-07-2017, 03:36 PM   #7
chatumao
LQ Newbie
 
Registered: Jul 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
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.
 
Old 03-07-2017, 04:20 PM   #8
goumba
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
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by chatumao View Post
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.
 
Old 03-07-2017, 04:35 PM   #9
chatumao
LQ Newbie
 
Registered: Jul 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
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!
 
  


Reply

Tags
bash, shell



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
[SOLVED] slocate/bash strange behavior. stf92 Slackware 9 09-25-2013 12:28 PM
Strange behavior when killing bash through a script alirezan1 Linux - Newbie 3 03-12-2009 07:29 PM
awk strange behavior in bash bingmou Linux - Software 7 09-18-2008 11:27 AM
strange sed/bash behavior mpdavig Programming 1 07-24-2004 02:27 AM
Strange Script Behavior Stranger Linux - General 0 02-18-2004 03:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:26 AM.

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