0

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)

  1. tried to implement latest echo $i which is A B C D
    cp -v ~/Desktop/library/template.cpp "$i".cpp
    didn't work

  2. tried another way. declaring the variable $i to the variable $filenames
    couldn't implement it correctly

Could anyone please help me out?

0 Answers0