0
#!/bin/bash
echo "this script will exchange the file name"
echo
read -p "please input you first file name: " f
read -p "please input you second file name: " s
if [ -f $f -a -f $s ]
then
mv $f "$f".bak
mv $s "$s".bak
mv "$s".bak $f
mv "$f".bak $s
fi
echo "this script will exchange the file name"
echo
read -p "please input you first file name: " f
read -p "please input you second file name: " s
if [ -f $f -a -f $s ]
then
mv $f "$f".bak
mv $s "$s".bak
mv "$s".bak $f
mv "$f".bak $s
fi
0
read -p "please input a filename: " a
read -p "please input a filename: " b
cat $a
cp $a /tmp/s.txt
cat "$b" > $a
cat /tmp/s.txt > $b
cat $a
read -p "please input a filename: " b
cat $a
cp $a /tmp/s.txt
cat "$b" > $a
cat /tmp/s.txt > $b
cat $a
0
- #!/bin/bash
- read -p "plese input filename 1:" a
- while :;do
- if [ ! -f "$a" ];
- then
- echo "The file is not found"
- read -p "plese input filename 1:" a
- else
- break;
- fi
- done
- read -p "plese input filename 2:" b
- while :;do
- if [ ! -f "$b" ];
- then
- echo "The file is not found"
- read -p "plese input filename 2:" b
- else
- break;
- fi
- done
- echo "wait for a minutes"
- mv $a $a.bak
- mv $b $a
- mv $a.bak $b
- sleep 1
- echo "It's OK!"
0
#!/bin/bash read -p "Please input a filename:" x read -p "Please input another filename:" y touch xz /bin/cp $x xz /bin/cp $y $x mv xz $y
0
本帖最后由 幻夜猫儿 于 2016-8-27 23:24 编辑
- #!/bin/bash
- #
- #
- /bin/mv file1 /tmp/
- /bin/mv file2 file1
- /bin/mv /tmp/file1 file2
0
#!/bin/bash
dir=/usr/local/sbin/test
cp $dir/$2 $dir/$2.bak
rm -f $dir/$2
mv $dir/$1 $dir/$2
mv $dir/$2.bak $dir/$1
dir=/usr/local/sbin/test
cp $dir/$2 $dir/$2.bak
rm -f $dir/$2
mv $dir/$1 $dir/$2
mv $dir/$2.bak $dir/$1
0
#!/bin/bash
#Auth: Cityzen Wang
#Date: 2017-05-01
#Scripts: Change filename for two files
a=`ls $1`
b=`ls $2`
mv $2 tmpfile
mv $1 $2
mv tmpfile $1
0
#Auth: Cityzen Wang
#Date: 2017-05-01
#Scripts: Change two files
function changefile() {
a=`ls $file1`
b=`ls $file2`
mv $file2 tmpfile
mv $file1 $file2
mv tmpfile $file1
}
while :
do
read -p "Please input two file: " file1 file2
if [ ! -e $file1 ] || [ ! -e $file2 ];then
echo "Two files must all exist!"
elif [ -d $file1 ] && [ -d $file2 ];then
changefile
exit
elif [ -f $file1 ] && [ -f $file2 ]; then
changefile
exit
else
echo "Can not change filename between Directory and File"
fi
done
改了一下,增加了判断语句
#! /bin/bash#Auth: Cityzen Wang
#Date: 2017-05-01
#Scripts: Change two files
function changefile() {
a=`ls $file1`
b=`ls $file2`
mv $file2 tmpfile
mv $file1 $file2
mv tmpfile $file1
}
while :
do
read -p "Please input two file: " file1 file2
if [ ! -e $file1 ] || [ ! -e $file2 ];then
echo "Two files must all exist!"
elif [ -d $file1 ] && [ -d $file2 ];then
changefile
exit
elif [ -f $file1 ] && [ -f $file2 ]; then
changefile
exit
else
echo "Can not change filename between Directory and File"
fi
done
编辑回复