give yourself a working bin directory, copy the script in there, and replace the directory names with surrogates.
in your .profile
ORIGINAL_PATH=${ORIGINAL_PATH:=$PATH}
PATH=$HOME/bin:${ORIGINAL_PATH}
export ORIGINAL_PATH
guarantees you always have a consistent PATH,
then at the command line:
$ mkdir $HOME/bin
$ cp {the script you need} $HOME/bin
$ pushd $HOME/bin
$ vi {the script}
changing the names of those unwriteable directories to something you can get at. so, you might:
$ pushd # might take you HOME, if not cd $HOME
$ mkdir sbox # your "sandbox"
$ pushd sbox
$ mkdir -p a/path/to/a/previously/unwriteable/ ...
this latter creates a directory:
$HOME/sbox/a/path/to/a/previously/unwriteable/
I've found it useful to use positional parameters, rather than cutting and pasting longwinded file paths. If you're going to use a name repeatedly, then do something like this:
$ set /DIR/Whichheld $HOME/sbox a/path/to/a/previously/unwriteable filename
$ echo $# $*
then this
$ cp $1/$3/$4 $2/$3/$4
takes care of one file. If you're needing a lot of copies:
$ from=$1/$3
$ to=$2/$3
$ pushd $from
$ cp * $to
$ popd
$ pushd $to
will copy all the files in FROM to TO...
and good luck.
chroot
to give the script a displaced root directory would work, but would require you to populate the hierarchy with all the associate infrastructure (any executables used, the needed shared libraries, and necessary device files). Another way would be to rewrite the script to require relative paths throughout, rather than absolute paths. This may or may not be possible, of course. – Kusalananda May 06 '17 at 12:06fakeroot
and friends – Chris Davies May 06 '17 at 12:22#!/bin/sh
instead of#/bin/sh
. There is a significant difference. Without the!
your first line is just a comment. – Tigger May 07 '17 at 06:45