Given two scripts
foo.sh
bar.sh
copied under /Contents/Resources in an .app bundle, where foo.sh
#!/bin/bash
. ./bar.sh
echo $1
Do get an error of
No such file or directory
on the line where the script tries to source bar.sh
Is there a way to relatively reference bar.sh?
Is there another way to bundle a set of bash scripts in a .app?
What you can do is:
Simple Example:
$cat script2
#! /usr/bin/env bash
echo "Hello World, this is script2"
$cat script1
#! /usr/bin/env bash
echo "Hello World from script 1"
echo "Full script path: $BASH_SOURCE"
echo "extracted directory: $(dirname $BASH_SOURCE)"
echo "running script 2"
$(dirname $BASH_SOURCE)/script2 && echo "running script 2 successful" || echo "error running script 2"
echo "sourcing script 2"
source $(dirname $BASH_SOURCE)/script2 && echo "sourcing script 2 successful" || echo "error sourcing script 2"
Test:
$ls /tmp/test
script1 script2
$pwd
/home/michael
$/tmp/test/script1
Hello World from script 1
Full script path: /tmp/test/script1
extracted directory: /tmp/test
running script 2
Hello World, this is script2
running script 2 successful
sourcing script 2
Hello World, this is script2
sourcing script 2 successful
See link above for more in detail discussion ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With