Hi,
Quote:
How to use a variable in a command in bash?
e.g.
$role="operator"
/usr/bin/passwd -u $role >& /dev/null
|
Your example is almost correct.
This: $role="operator" should be:
role="operator" (the variable has no leading $).
Quote:
How to change only the first character to upper case?
|
Using a perl one-liner is probably the easiest:
$ echo $role
operator
$ echo $role | perl -ne 'print ucfirst($_)'
Operator
If perl is not an option, you could write a function:
Code:
capitalize_first ()
{
string0="$@"
firstchar=${string0:0:1}
string1=${string0:1}
FirstChar=`echo "$firstchar" | tr a-z A-Z`
echo "$FirstChar$string1"
}
The above code separates the first char from the input (firstchar=${string0:0:1} and string1=${string0:1}), capitalizes the first char (FirstChar=`echo "$firstchar" | tr a-z A-Z`) and returns the result (echo "$FirstChar$string1").
Both variables and 'normal' input is accepted:
$ echo $role
operator
$ capitalize_first $role
Operator
$ capitalize_first operator
Operator
BTW: Here's a bash very usefull bash guide:
Advanced Bash-Scripting Guide
Hope this helps.