当前位置:  技术问答>linux和unix

关于脚本编写得几个问题

    来源: 互联网  发布时间:2015-10-05

    本文导语:  2.Create a shell program called my_ask.sh that will ask the user if he or she would like to see the contents of the current directory. Inform the user that you are looking for a yes or no answer.Issue an error message if the user does not ...

2.Create a shell program called my_ask.sh that will ask the user if he or she would like to see the contents of the current directory. Inform the user that you are looking for a yes or no answer.Issue an error message if the user does not enter yes or no. If the user enters yes display the contents of the current directory. If the user enters no, ask what directory he 
or she would like to see the contents of. Get the user's input and display the contents of that directory. Remember to verify that the requested directory exists prior to displaying its contents.
#!/bin/bash
#This script Create a shell program called my_ask.sh that will ask the user if he or she would like
#to see the contents of the current directory. Inform the user that you are looking for a yes or no 
#answer.Issue an error message if the user does not enter yes or no. If the user enters yes display 
#the contents of the current directory. If the user enters no, ask what directory he 
#or she would like to see the contents of. Get the user's input and display the contents of that 
#directory. Remember to verify that the requested directory exists prior to displaying its contents.
echo -e "Would you like to see the contents of the current directory? [yes/no]c"
read answer
if [ "$answer" = "yes" -o "$answer" = "y" ] ; then
  ls -l $PWD
elif [ "$answer" = "no" -o "$answer" = "n" ] ; then
  echo "Which directory would you like to see?(Plz input the standard patch,such as /home/user/)"
  read answer2;ls -l $answer2
else
 echo "Error input!"
fi

3.Create a shell program called my_menu.sh that will display a simple menu that has three options.
    a. The first option will run who;
    b. The second option will run pwd;
    c. Quit
   The menu should be redisplayed after each selection is completed, until the user enters 3 .

#!/bin/sh
echo Please choose your option...
echo "a. The first option will run who;"
echo "b. The second option will run pwd;"
echo "c. Quit"
read answer
case "$answer" in
   [aA]  ) who ;;
   [bB]  ) pwd ;;
   [cC3] ) exit ;;
      *  ) echo wrong choose ;;
esac

4.Create a program my_cp.sh which will copy one file to another. The program will accept two command line arguments, a source and a destination. Check for the following
   situations:
    a) It should make sure that the source and destination do not reference the same file.
    b) The program should verify that the destination is a file.
    c) The program should verify that the source file exists.
    d) The program should check to see if the destination exists. If it does, ask the user if he or she wants to overwrite it.

#!/bin/sh
echo "Please input the name of the file:n"
read file
if test ! -f $file ;then     # check if $xx is not existed and is not a valid regular file
 echo $file is not existed or is not a regular file
 continue # return back to line number 1
fi # if construct finish
echo " Please input the name of the directory you want to copy: n"
read dir
if test ! -d $file ;then     # check if $dir is not existed and is not a valid regular directory
 echo $dir is not existed or is not a regular directory.
continue # return back to line number 1
fi # if construct finish
echo copy $file
cp -i $file $dir   #copy file
break
done    # loop finished
echo program finished
exit

|
不知道你想说什么问题?

    
 
 

您可能感兴趣的文章:

  • 关于shell定时器脚本的几个问题(附源代码)
  • 脚本如何自动输入密码??交互式脚本如何编写?
  • Linux下如何编写脚本文件
  • 请问脚本编写的一些问题?
  • solaris 下怎样编写脚本创建自己应用程序的图标?
  • 求shell脚本编写
  • 请教一个脚本编写时的问题
  • 请问怎样用shell脚本编写Linux下的文件备份程序
  • 如何用shell编写一个脚本文件?
  • shell脚本编写
  • 求教:编写一个bash脚本程序执行一个./file 程序
  • 急问:怎样用shell编写脚本运行要输入密码的程序???
  • Expect脚本的编写
  • 关于linux下打开terminal的脚本的编写
  • 编写一段B-Shell脚本程序,读入10个整数,打印它们的累加和
  • 在AIX系统中编写的脚本里如何去的系统时间
  • Kill 脚本编写!
  • 编写脚本:怎样在vmstat 1产生的结果中,在每行前面加上当前时间
  • 删除文件的shell脚本编写,条件内详
  • 关于邮件通知的脚本编写
  • bash脚本编写求助
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 红帽redhat下通过脚本和yum安装docker容器引擎的详细步骤
  • 脚本1调用脚本2,脚本2必须输入回车,如何在调用过程中自动输入回车
  • HTML 脚本语言介绍及<script>标签用法
  • 脚本中如何调用另外的一个脚本?
  • 脚本调用脚本出异常
  • shell 脚本中命令别名在脚本外无法使用
  • 想用shell脚本定时执行另一个脚本
  • shell脚本问题 关于父脚本和子脚本的问题
  • centos系统运行脚本,显示bash进程,能否以脚本名字显示?
  • 求救:修改系统启动脚本 不过脚本里面误写了阻塞命令
  • 如何传递参数给linux shell 脚本(当脚本从标准输入而不是从文件获取时)
  • 定时跑脚本编译C文件就报错,手动跑脚本就编译成功了.
  • 请问在 LINUX下如何编辑脚本(可以直接运行脚本访问WINDOW系统)
  • 请问在脚本里怎么得到一个程序运行的返回值,脚本怎么返回值?
  • C语言调用shell脚本后,通过何种方法能获取脚本中变量的值
  • 请教一个问题,CRONTAB执行脚本和SSH登陆后调用脚本有什么不同?
  • windows上脚本调用UNIX的脚本
  • shell脚本如何调用另外一个shell脚本的函数?
  • 急救!关于Shell脚本删除过期文件的问题,Shell脚本达人乱入
  • 如何给shell脚本加密,脚本中有密码。最好是比较直接的,不要说让用 shc
  • Shell脚本调用Sql脚本并向其中传递变量


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3