I am accepting a few strings as user input to my script like -
read -p "User's full name : " FULLNAME
read -p "User's Manager's name : " MGRNAME
.
.
I want all input strings be capitalized, i.e. capitalize each word in the input string.
I wrote a simple function like -
capitalize()
{
$1=`echo ${$1}|sed -e "s/\b\(.\)/\u\1/g"`
}
and called this function as -
capitalize FULLNAME
It is giving the below error -
line 77: ${$1}: bad substitution
Also tried indirect expansion -
capitalize()
{
$1=`echo ${!1^}`
}
It throws the below error -
line 77: FULLNAME=Kamlesh: command not found
Please help with the correct syntax or any other way to achieve this.
Sample Output - I am reading the input in FULLNAME variable. When I am calling capitalize(), it should update the value within FULLNAME variable itself.
For e.g., if the user input is - "kamlesh gallani"
If I call capitalize FULLNAME now, then FULLNAME should contain "Kamlesh Gallani"