0

I have a script:

$cat ifile.sh
extension="name.f"
parameter_list="abc,xyz,stuv,ptq,rhu"
echo newfiles are $parameter_list

I would like to execute the ifile.sh and output should replace the comma , with extension i.e. _name.f. So my desire output will be

$sh ifile.sh
newfiles are abc_name.f xyz_name.f stuv_name.f ptq_name.f rhu_name.f

So I need to modify the echo newfiles are $parameter_list. I am trying with the follwoing

$cat ifile.sh
extension="name.f"
parameter_list="abc,xyz,stuv,ptq,rhu"
echo newfiles are sed -i 's/,/$extension/g' $parameter_list

1 Answer 1

1

Use a parameter expansion.

echo "newfiles are ${parameter_list//,/_$extension }_$extension"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.