I have been looking on Google for quite a while now and can’t find anything that is matching what I need/want to do.
My objective is to write a script that takes two arguments. It will search through the first argument (which is a list) and detect if the second argument is already in it. For example:
list = /bin/foo:/bin/random:random
to add to list: /bin/foobar
Calling the script will produce the result of /bin/foo:/bin/random:random:/bin/foobar.
If the part to add to the list is already in the list then nothing will be changed of the original.
I have everything working up until the point where I want to modify the parameter I passed.
...
if [ $RUN = 1 ]; then
echo $1
else
$1="$NEWLIST"
fi
exit 0
This however produced an error. It says that the command isn’t found and gives me the line number that $1=”$NEWLIST” is on. What am I doing wrong here? How do I modify $1? Thanks!
edit:
$ PATH=/opt/bin:$PATH
$ ./scrip.sh PATH /user/opt/bin
$ /opt/bin:/user/opt/bin
This is what I would want as a result of the script.
adymitruk already said it, but why do you want to assign to a parameter. Woudln’t this do the trick?
Maybe this:
BIG EDIT:
Use this script (called listadd for instance):
And source it from your shell. Result is the following (I hope this is what wsa intended):