-2

I have this issue of "./script1.sh not found" when called from another script2.sh which is actually bounded to a keyboard shortcut (control+e).

When I press control+e the script2.sh instantly opens up a new terminal and starts performing its task, but when it has to make a call to script1.sh, it shows this error i.e: sh: 1: ./script2.sh: not found

it works fine when I run it manually in the terminal which is meant to be the current working directory i.e HOME, but it doesn't work when starts from the shortcuts i.e control+e, it perform half its task.

The problem is that these scripts have set different paths as "./exampleProgam" or "./exampleScript" and doesn't have a full path like "/home/user/program" or "/home/user/script" .

So i don't want to go throw around 70 files and manually change paths one by one to full paths like "/home/user/folder". I will also have to write extra code in order to get the home dir path.

All these scripts and C programs are placed in one folder i.e folder1 in the home direcory: /home/user/folder1/script2.sh while script1.sh is placed in the

/home/user/script1.sh

.

and where does the terminal shell opens up by default.?? becuase when i press the control+e and the program starts in the shell , it doesn't shows any path etc but just starts executing.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
shinwari_afg
  • 104
  • 11
  • Don't complain that it's not working if you don't want to do it right. You'd have to touch it anyway, because the ./ makes it a path as well, that being the current working directory. If you JUST used names and added all directories to the PATH that might work (would open a can of worms and be an **ugly** kludge). Just edit your scripts, potentially using sed ... – tink Aug 29 '17 at 21:08
  • @tink I do want to do it right and i did it right by selecting the ./ current working directory for my whole project and it runs everywhere in the filesystems, except now when i'm trying to bound the whole program to a keyboard shortcut..The real problem is that i don't know where and in which directory does the terminal shell starts when it is started and invoked by a script.?? because it starts in some unknown directory where my program files/scripts are not placed neither on the desktop neither in the home directory. – shinwari_afg Aug 29 '17 at 21:41
  • See [BashFAQ #28](http://mywiki.wooledge.org/BashFAQ/028), which is directly on-point for what you're actually trying to do. – Charles Duffy Aug 29 '17 at 21:58
  • ...indeed, I think there's an argument that this may be duplicative of [Getting the source directory of a bash script from within](https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within). Or, at least, with other questions that are defensibly already marked duplicate of same (ie. [Relative paths based on file location instead of current working directory](https://stackoverflow.com/questions/24112727/shell-relative-paths-based-on-file-location-instead-of-current-working-director?noredirect=1&lq=1)). – Charles Duffy Aug 29 '17 at 21:59
  • @CharlesDuffy not a duplicate but possibly ill written question by me, it is 3:25Am , my head and whole body hurts...couldn't ask it clearly and hence getting the down votes as well. – shinwari_afg Aug 29 '17 at 22:26
  • @CharlesDuffy I will edit it maybe later. – shinwari_afg Aug 29 '17 at 22:27
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Mar 24 '18 at 07:53

1 Answers1

0

I would strongly recommend you to go ahead and fix the path actually.

Or maybe you could add your code and ask for help on how to edit/modify those lines (maybe using sed, as mentioned in the comments)/

But since you have not shown your code, and if its really that hard to correct it now, maybe you can try adding cd /home/user/script/ as the first line in your script1.sh file. This will change the current directory for further commands.

zeekhuge
  • 1,594
  • 1
  • 13
  • 23
  • The real problem is that i don't know where and in which directory does the terminal shell starts when it is started and invoked by a script.?? because it starts in some unknown directory where my program files/scripts are not placed neither on the desktop neither in the home directory........ – shinwari_afg Aug 29 '17 at 21:49
  • ......The whole program has no issues with paths at all whether runs in home or in Desktop directory or somewhere else, and as i said the program has paths specified as "./script.sh" when it has to call to a script which is located in the same directory....The problem occurs when this same program is invoked by a keyboard shortcut which automatically opens a new terminal shell, and i don't know in which directory does this shell runs.??? I didn't posted any code because it is not about code, more about binding an application to keyboard key which runs in the terminal. – shinwari_afg Aug 29 '17 at 21:49
  • well then, just add `echo $PWD` in your code and see ... I tried and noticed thats its my home dir – zeekhuge Aug 29 '17 at 21:56