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
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 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
How to change the login shell?
Answer:
To change the current user login shell, use the following command
e.g. change to /bin/sh
chsh -s /bin/sh
Logout and login again.