I have a interactive Bash script, conozcoArrays.sh
,
#!/usr/bin/bash echo -e "\nGive me their phone number?\n" read number TOGOes=("$(find ~/chicas -maxdepth 1 -iname "*$number*" -type d -execdir echo {} + | sed "s;./;${HOME}/chicas/;g")" "$(find ~/chulos -maxdepth 1 -iname "*$number*" -type d -execdir echo {} + | sed "s;./;${HOME}/chulos/;g")" "$(find ~/parejas -maxdepth 1 -iname "*$number*" -type d -execdir echo {} + | sed "s;./;${HOME}/parejas/;g")" ) for togo in "${TOGOes[@]}" do if [[ $togo != "" ]]; then echo $togo export togo && cd $togo && return 0 else echo "Haven't found her in my directories." && cd ~/chicas fi done
that performs a search in my directories for a keyword, and if it finds anything it changes to this directory. For this reason I usually launch it sourcing it, like so . ~/CS/SoftwareDevelopment/MySoftware/Bash/pasion/conozcoArrays.sh
I also have another Bash script, todo.sh
, that references 'conozcoArrays.sh':
#!/usr/bin/bash ita='\e[3m' end='\e[0m' echo -e "1. La conozco? 2. Search through websites for a given phone number and create a dossier. 3. {ita}escort-scraper.py{end}" read ch if [[ "${ch}" == '1' ]]; then . ~/CS/SoftwareDevelopment/MySoftware/Bash/pasion/conozcoArrays.sh elif [[ "${ch}" == '2' ]]; then "${HOME}/CS/SoftwareDevelopment/MySoftware/Python/escorts/search-no.py" elif [[ "${ch}" == '3' ]]; then "${HOME}/CS/SoftwareDevelopment/MySoftware/Python/escorts/escort-scraper.py" fi
The issue is that when I enter 1
conozcoArrays.sh
is not evaluated, it is launched but it does not seem to be sourced - I expect to be in a different directory after the todo.sh
script finishes but I'm not. How might I source conozcoArrays.sh
from another interactive script?
todo.sh
in the first place?conozcoArrays.sh
is being sourced, what makes you think it isn't? Are you expecting to be in a different directory after thetodo.sh
script finishes?todo.sh
script finishes" for that to happentodo.sh
must be sourced.todo.sh
print the directory instead ofcd
-ing your calling shell to it so you can docd "$(todo.sh)"
instead of. todo.sh
to avoid any undesirable side-effects from everything else thattodo.sh
might do beyond changing directory if you source it.