My bash script
#!/bin/bash
read -r -p "Enter the filenames: " -a arr
for i in "${arr[@]}"
do
echo "$i" | sed 's/\(.*\)\..*/\1/'
# -- problem in this area --
filenames="$i"
#declare -a $filenames=$i
# -- upto this line ---
cp -v ~/Desktop/library/template.cpp "$filenames".cpp
done
With the help of this code echo "$i" | sed 's/\(.*\)\..*/\1/'
If number of inputs are A B.cpp C D.cpp
, it will turn to A B C D
I need A B C D
to go into for-loop
and become A.cpp B.cpp C.cpp D.cpp
My problem: I'm not being able do that. (Failed)
tried to implement latest
echo $i
which isA B C D
cp -v ~/Desktop/library/template.cpp "$i".cpp
didn't worktried another way. declaring the variable
$i
to the variable$filenames
couldn't implement it correctly
Could anyone please help me out?
$i
using the shell's own parameter expansion${i%.*}
– steeldriver Jan 14 '22 at 14:51