yish8213
3/27/2016 - 10:30 PM

Simple bash script

Simple bash script

#!/bin/bash

# We can find another test method through 'man test' command
if [ -z $1 ]; then
        echo "No pattern given."
        echo "Usage: $0 <pattern>"
        exit
fi

# We declare two variables for the two directories

pattern=$1
firstdir=dir1
seconddir=dir2

# The for loop that moves the right files

for i in 'grep -l "$pattern" $firstdir/*'; do
        mv $i $seconddir
        echo $i
done
# for i in {command}; do {command}; done
for i in 'ls *.text'; do mv $i $i.old; done

# while read filename; do {command}; done < ./filelist.txt
while read filename; do mv $filename $filename.old; done < ./filelist.txt