Re: [Help-bash] No tilde expansion in [[..]] when reading input with rea
From:
Chris Down
Subject:
Re: [Help-bash] No tilde expansion in [[..]] when reading input with read
Date:
Mon, 25 Feb 2013 22:35:01 +0800
User-agent:
Mutt/1.5.21 (2010-09-15)
On 2013-02-25 08:37, Greg Wooledge wrote:
> Ironically, stripping all characters except alphanumeric, underscore,
> and maybe a few other well-chosen bits of punctuation, and then using
> eval, may be the safest and most portable way to go.
>
> IFS= read -r raw_username
> username=${raw_username//[![:alnum:]_.-]/}
> if [[ $username = "$raw_username" ]]; then
> eval "home=~$username"
> echo "home=<$home>"
> else
> echo "Nice try, but no."
> fi
Aren't some of the excluded characters legal on some Unices, though? If I recall
correctly, some are constrained by NAME_REGEX rather than actual limitations in
storing user metadata. Perhaps I remember wrongly.
Chris