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
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.
Run all scripts under in a directory
Answer:
Create the following bash script, and execute it
for FILE in /project/scripts/*.sh
do
if [-f $FILE -a -x $FILE]
then
$FILE
fi
done
How to mass rename file in Bash
Answer:
For example, you might want to rename *.htm to *.html, create the following scripts
vi rename.sh
And enter
#!/bin/bash
for f in *.htm; do
mv $f ${f%htm}html
done
Execute the script and it does all the rename magics.
Convert IP address to HEX in Bash script
Answer:
The following Bash script is useful to convert IP address to HEX
#!/bin/sh
IP_ADDR=192.168.1.234
printf '%02X' ${IP_ADDR//./ }; echo