• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Bash shell scripting question....

Superwormy

Golden Member

Below is my shell script... I just can't get it to fill in the $username var in the perl commands I want to execute. It should end up running a command like this:

perl -i -e 's/keithpalmerjr/KeithPalmerJr/g' /etc/gshadow

But instead, I get one of these two, depending on how I muss with the code trying to get it to work:
perl -i -e 's///g' /etc/gshadow
perl -i -e 's/$lowercase_username/$username/g' /etc/gshadow

What am I doing wrong?



== bash function ==

mixedcase_user_to_lowercase()
{
username=$1

echo "Operating on user: $username"

echo " Converting $username to lowercase..."
lowercase_username=`echo $username | tr A-Z a-z`
echo " Converted to $lowercase_username"

echo " Adding user $lowercase_username"
`adduser -m $lowercase_username`

echo " Running gigantic perl command for user $lowercase_username"
`perl -i -e 's/$lowercase_username/$username/g' /etc/passwd`
`perl -i -e 's/$lowercase_username/$username/g' /etc/shadow`
`perl -i -e 's/$lowercase_username/$username/g' /etc/group`
`perl -i -e 's/$lowercase_username/$username/g' /etc/gshadow`
`mv /home/$lowercase_username /home/$username`
`chown -R $username:$username /home/$username`

echo ""
}
 
you shouldn't need to surround your commands with backticks (unless you're assigning them to a variable). That might do it if it's handling the backticked string without interpreting.
 
perl -i -e 's/'$lowercase_username'/'$username'/g' /etc/passwd

What about like that? (put ' around variable names?) I haven't tested it. I don't know what it's supposed to do, but it looks like it's executing this if I echo it:

perl -i -e s/asdf/asdf/g /etc/passwd
 
Back
Top