Assign Output of Shell Command To Variable in Bash

var=$(command-name-here)
var=$(command-name-here arg1)
var=$(/path/to/command)
var=$(/path/to/command arg1 arg2)

OR use backticks based syntax as follows to assign output of a Linux command to a variable:

var=`command-name-here`
var=`command-name-here arg1`
var=`/path/to/command`
var=`/path/to/command arg1 arg2`

Examples

## store date command output to $now  ##
now=$(date)
## alternate syntax ##
now=`date`

To display back result (or output stored in a variable called $now) use the echo or printf command:

echo "$now"
printf "%s\n" "$now"

References
https://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output/

MySQL Error: : ‘Access denied for user ‘root’@’localhost’

sudo mysql
-- for MySQL
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

-- for MariaDB
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');

With a single query we are changing the auth_plugin to mysql_native_password and setting the root password to root and there isn’t any need to restart mysqld or start it with special privileges.

References
https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost

Convert MP4 video to MP3 audio with FFmpeg

ffmpeg -i filename.mp4 filename.mp3

fixed bit rate :

ffmpeg -i video.mp4 -b:a 192K -vn music.mp3

variable bit rate :

ffmpeg -i in.mp4 -q:a 0 -map a out.mp3

variable bit rate of 165 with libmp3lame encoder :

ffmpeg -vn -sn -dn -i input.mp4 -codec:a libmp3lame -qscale:a 4 output.mp3
  • -vn disables all video-streams from the input
  • -sn disables all subtitle-streams from the input
  • -dn disables all data-streams from the input
  • -i specifies the input file
  • -codec:a libmp3lame specifies the encoder
  • -qscale:a 4 specifies the quality target for libmp3lame
  • The last argument is the output-file. Note that the file-extension might be used to infer additional information.

References
https://superuser.com/questions/332347/how-can-i-convert-mp4-video-to-mp3-audio-with-ffmpeg
https://superuser.com/questions/1463710/convert-mp4-to-mp3-with-ffmpeg