Linux简单脚本编写

2、编写一个脚本,用于将多次输入的字符组合为一个字符串要求:使用循环语句完成多个字符的输入,直到输入字符串EOF才完成字符串的累加3、自我练习:设计一个运算器,用来完成下列功能i)四则运算:符号使用+、-、*、/ii)乘方运算:0次、1次、2次、3次、4次、5次幂,幂级和底数均由用户给出4、自我练习:对两个给定文件执行给定操作。要求:i)用户输入两个文件的名称 ii)分别判断这两个文件是否存在 iii)判断这两个文件的类型是否相同 iv)判断这两个文件的拥有者操作权限是否相同 v)若这两个文件都存在,且类型和操作权限都相等,则将较新的文件复制到目录/tmp中,并提示用户复制成功;若两者的时间相同,则不做复制操作,并提示用户两文件时间相同。能帮写出来几题就写出来几题吧.....就是sh那种脚本的,用Bin/bash

2、

#!/bin/bash
while read LINE
do
ass="$ass$LINE"
case $LINE in
EOF) exit ;;
esac
echo "$ass"
done

4、
#!/bin/bash
_type1=`file $1 | cut -d" " -f2-`
_type2=`file $2 | cut -d" " -f2-`
_time1=`ls -l $1 | awk '{print $6,$7,$8}'`
_time2=`ls -l $2 | awk '{print $6,$7,$8}'`

test -f $1 && test -f $2 && [ "${_type1}" = "${_type2}" ] && find -perm 644 | grep -E "$1|$2" >/dev/null 2>&1

if [ $? = 0 ];then
if test $1 -nt $2 ; then
cp $1 /tmp && echo "Copy is ok"
fi
if test $2 -nt $1 ; then
cp $2 /tmp && echo "Copy is ok"
fi
if [ "${_time1}" = "${_time2}" ];then
echo "The time of two files is as well."
fi
else
echo "File is different."
fi
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-20
3、
#!/bin/bash

operator="+ - x / exit"
echo -n "please input two digits:"
read number1 number2
echo number is: $number1 $number2
select i in $operator
do
case $i in
+)result=$(($number1+$number2));
echo "The result is:$result";;
-)result=$(($number1-$number2));
echo "The result is:$result";;
x)result=$(($number1 * $number2));
echo "The result is:$result";;
/)result=$(($number1 / $number2));
echo "The result is:$result";;
exit)
echo "bye";exit;;
esac
done
相似回答