I am renaming some files.
This works:
ls | while IFS= read -r line; do name=$(echo $line | sed -e 's/\(.*\)/\1.jpg/') && mv $line $name; done
Which is okay but I'd like to make it more concise, like:
ls | while IFS= read -r line; do name=$(sed -e 's/\(.*\)/\1.jpg/' $line) && mv $line $name; done
The latter example and various similar attempts pass the file into sed rather than the value of the variable.
Using ˋ$line
ˋ and $($line)
both result in an attempt to execute the file. While variations of "$line"
, 'line'
with and without <
, all lead to the file be read in. What is going on here? Can the $line
variable be used directly with sed for this purpose?
<<< "$line"
- however, you should really rethink your entire approach. Do you really need anything more thanfor f in *; do mv -- "$f" "$f.jpg"; done
? – steeldriver Jan 10 '17 at 14:52<<< "$line"
is more readable thanecho $line | sed
. – dies_felices Jan 10 '17 at 15:50prename 's/$/.jpg/' *
– JJoao Jan 10 '17 at 16:10