3

When trying to execute a bash script, it is often execute inside some directory, and requires access to local resources. I was wondering if there was a way to combine both the bash script and the resources (everything else in the directory) into an executable, so that I would only need that executable stand-alone to execute the bash script.

7
  • shar(1) would be traditional, but why does it need to be a single executable, when you could instead use rsync or git or something to move a file tree around as needed?
    – thrig
    Jun 1, 2016 at 21:56
  • For convenience. For example, when I want to run the script from /usr/local/bin, I don't want to move the whole directory to /usr/local/bin - I think it would be more convenient to move just the combined executable.
    – UCLA
    Jun 1, 2016 at 22:07
  • This sounds messy and fragile. You shouldn't be moving scripts around like that, and definitely not into directories owned by root, unless you know exactly what you're doing. Why can't you just pass the directory you want the script to work on as a command-line argument? Are you aware of the pwd command? Also, you can store the name of the directory containing the resources your script needs in a variable in the script, or pass it in on the command-line.
    – PM 2Ring
    Jun 1, 2016 at 23:10
  • 1
    FWIW, depending on your system, a script on your PATH may be able to determine the full name of the directory it is stored in (no matter what your current directory is) by doing, eg home=$(dirname $(readlink -e $0)), but hopefully you shouldn't need to do that.
    – PM 2Ring
    Jun 1, 2016 at 23:11
  • I can and I am aware of ways to get a bash script to use a directory. For exampe when running cron jobs I just cd into the desired directory. Problem is that this is hardcoded and I need to change it everytime I move to a new system. Was just wondering if there was a more elegant way so that I could combine everything into one file (executable) and just move that thing around anyway I want without having to change things every time.
    – UCLA
    Jun 2, 2016 at 0:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.