0

I am generating the random string to change the password of users by shell scripting. I am using the below command to generate the random string

 </dev/urandom tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | head -c 13  ; echo

I am not able to put this on a variable.

1 Answers1

1

I'm not sure what you've tried, but command substitution seems to work for me:

x=$(</dev/urandom tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | head -c 13  ; echo)
echo "$x"

If this doesn't work for you then you might want to update the post with more information.

igal
  • 9,886
  • 1
    You should double-quote the variable reference (i.e. echo "$x") -- the character list doesn't include spaces, but it does include shell wildcard characters, which have the potential to cause weird results if not quoted. – Gordon Davisson Oct 27 '17 at 06:17