I imagine that you have files in a place (/path/to/originals
) and want to copy them to a target location (/path/to/destination
) and modify them afterwards. Your current script looks like:
mkdir /path/to/destination cp /originals/this-file /path/to/destination cp /originals/this-other-file /path/to/destination modify-somehow /path/to/destination/this-file modify-somehow /path/to/destination/this-other-file
but you don't like to have to hardcode /path/to/destination everywhere. So you can ask to use "the value of the first positional parameter" instead of hardcoding /path/to/destination
. As others mentioned, the value of the first positional parameter is $1
.
So your script should be:
mkdir $1 cp /originals/this-file $1 cp /originals/this-other-file $1 modify-somehow $1/this-file modify-somehow $1/this-other-file
And you should invoke this by adding the destination path as an argument:
my-script /path/to/destination
I tried to keep the script simple, but you could improve it, like using a single cp
command to copy several files. You can also use a variable for your /originals
path (but instead of an argument, this one sounds like a constant declaration at the beginning of your script)
Lastly, consider that if your filenames have spaces, you'll need to surround your $1
in double quotes.