for f in /path/to/dir/*.c~; do
# if it is a file, delete it
if [ -f $f ]
then
rm "$f"
fi
done
For While Loop Through File Contents Script
while COMMANDS
do
COMMANDS
done
OR
while read line
do
echo "$line"
done < /path/to/input.txt
In this example, read /etc/passwd file line by line using while loop:
#!/bin/bash
while IFS= read -r line
do
echo "$line"
done < "/etc/passwd"
|
Another example:
#!/bin/bash
## script.sh ##
_file="${1:-/dev/null}" #fail safe
while IFS= read -r line
do
# Do something on $line
echo "$line"
done < "$_file"
|
Run it as follows:
chmod +x script.sh
./script.sh /path/to/text/file.name
|
No comments:
Post a Comment