I tried using some variables to rename a few files, but it failed miserably. I've tried different ways of getting it to work, but to no avail. As far as I understand the documentation, this is the correct way of doing things - however now I'm stumped...
Here's the code (as written in the file rename_prefix.sh):
#!/bin/sh
NEWPREF="LALA"
OLDPREF="LULU"
for f in $OLDPREF*; do mv $f $(echo $f | sed 's/^$OLDPREF/$NEWPREF/g'); done
Here's the error message:
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
Initially I thought the problem lay in using variables with what I assume are the regular expressions, but as can be seen from the error messages, the problem lies where the variables are first declared.
What's going on here?
'. Try using double quotes"in thesedcommand e.g.sed "s/^$OLDPREF/$NEWPREF/g"or something similarNEWPREF ="LALA"in your script ?"$OLDPREF"in the glob, and definitely definitely shouldn't be recycling it for use as a regex. Use parameter expansion for string manipulation of shell variables if at all possible. Lots of quoting issues here.=to get those error messages. Try:od -xc rename_prefix.shto see "hidden" characters, like \r.