Answer the question
In order to leave comments, you need to log in
How to process a string in a bash script and pass the result to a variable?
The bash script has this command:
grep 'temporary password' /var/log/mysqld.log
It produces something like this:
2017-12-01T00:22:31.416107Z 1 [Note] A temporary password is generated for [email protected] : mqRfBU_3Xk>r
I want the script to extract the last 12 characters of this string and store them in a VAR variable.
I know how to do it in php and javascript but never wrote bash.
Thanks
Answer the question
In order to leave comments, you need to log in
line=`grep 'temporary password' /var/log/mysqld.log`
VAR=${line: -12}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question