0

Testing a batch script, I execute it in bash. I want to see prompts and respond by inputting variables.

For example, the following works, but I want to prompt for these inputs, not put literals in my script. So $1, $2 instead of these:

srcWidgetName="Foo"
newWidgetName="bar"

find . -type f -name "$srcWidgetName*" | while read -r file; do
    mv "$file" "${file//$srcWidgetName/$newWidgetName}"
done

1 Answers1

1

Is this what you are trying to do?

echo -n "Enter the source widget name [ENTER]: "
read srcWidgetName
echo -n "Enter the destination widget name [ENTER]: "
read dstWidgetName

find . -type f -name "$srcWidgetName*" | while read -r file; do
    mv "$file" "${file//$srcWidgetName/$dstWidgetName}"
done
user5870571
  • 3,094
  • 2
  • 12
  • 35