How to check the bash shell version
Answer:
To check the current bash shell version
# bash -version
GNU bash, version 3.2.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How to check the bash shell version
Answer:
To check the current bash shell version
# bash -version
GNU bash, version 3.2.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
How to execute a command repeatedly using bash
Answer:
The following simple bash script will run the echo command, sleep 10 seconds repeatedly.
#!/bin/bash
while [1];
do
echo "Hello!";
sleep 10;
done
Generate random number in Linux
Answer:
To generate a random number from 1 to 100, you can use the following simple command
# echo $((RANDOM%100+1));
76
You can replace 100 by the maximum value, and 1 by the minimum value.
How to get the PID in current bash shell script
Answer:
Use the special variable $$, you can get the PID (Process ID) of the current bash shell script
#/bin/bash
echo $$;
The above script will print the PID to the standard out.
How to list which login shells are available in the system
Answer:
View the file /etc/shells, and you will find all the valid login shells
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
...
/bin/bash