当前位置: 技术问答>linux和unix
请教shell的问题
来源: 互联网 发布时间:2015-08-23
本文导语: 1、分析下面shell脚本的功能: count=$# cmd=echo while [$count –gt 0] do cmd=”$cmd $$count” count=’expr $count – 1’ done eval $cmd 2、编写一个shell脚本,它把第二个位置参数及其以后的各个参数指定的文件复制到第一个位...
1、分析下面shell脚本的功能:
count=$#
cmd=echo
while [$count –gt 0]
do
cmd=”$cmd $$count”
count=’expr $count – 1’
done
eval $cmd
2、编写一个shell脚本,它把第二个位置参数及其以后的各个参数指定的文件复制到第一个位置参数指定的目录中。
3、编写一个shell脚本,显示当天日期,查找给定的某用户是否在系统中工作。如果他在系统中,就发一个问候给他。
$cat ex1
date
4、利用for循环将当前目录下的.c文件移到指定的目录下,并按文件大小排序,显示移动后指定目录的内容。
每题20分,在线等~谢谢!
count=$#
cmd=echo
while [$count –gt 0]
do
cmd=”$cmd $$count”
count=’expr $count – 1’
done
eval $cmd
2、编写一个shell脚本,它把第二个位置参数及其以后的各个参数指定的文件复制到第一个位置参数指定的目录中。
3、编写一个shell脚本,显示当天日期,查找给定的某用户是否在系统中工作。如果他在系统中,就发一个问候给他。
$cat ex1
date
4、利用for循环将当前目录下的.c文件移到指定的目录下,并按文件大小排序,显示移动后指定目录的内容。
每题20分,在线等~谢谢!
|
试着解决:
1、分析下面shell脚本的功能:
count=$# //count初始化为脚本参数个数
cmd=echo //cmd初始化为echo命令
while [$count –gt 0] //while循环,判断条件是:脚本参数的个数是不是大于0
do
cmd=”$cmd $$count” //把脚本参数$n逆序加到echo 后面
count=’expr $count – 1’ //将$count-1
done
eval $cmd //执行$cmd字符串表示的shell命令
最终结果是逆序打印脚本提供的参数;
例:
#./test.sh 1 2 3 4 5
5 4 3 2 1
#
1、分析下面shell脚本的功能:
count=$# //count初始化为脚本参数个数
cmd=echo //cmd初始化为echo命令
while [$count –gt 0] //while循环,判断条件是:脚本参数的个数是不是大于0
do
cmd=”$cmd $$count” //把脚本参数$n逆序加到echo 后面
count=’expr $count – 1’ //将$count-1
done
eval $cmd //执行$cmd字符串表示的shell命令
最终结果是逆序打印脚本提供的参数;
例:
#./test.sh 1 2 3 4 5
5 4 3 2 1
#
|
第二题:
#!/bin/bash
dir=$1
shift
while [$# -gt 0]
do
cp $1 $dir
shift
done
#!/bin/bash
dir=$1
shift
while [$# -gt 0]
do
cp $1 $dir
shift
done
|
第四题:
#!/bin/bash
name=`ls *.c`
for file in $name
do
mv $file yourdir # yourdir 是你指定的目录
done
cd yourdir
ls -l -S
其实不用 for 循环的,直接用:
mv $name yourdir
就行了!
#!/bin/bash
name=`ls *.c`
for file in $name
do
mv $file yourdir # yourdir 是你指定的目录
done
cd yourdir
ls -l -S
其实不用 for 循环的,直接用:
mv $name yourdir
就行了!