晒一下第一个脚本mount_iso.sh自动挂载iso文件

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
schspa
帖子: 49
注册时间: 2012-02-06 14:54
联系:

晒一下第一个脚本mount_iso.sh自动挂载iso文件

#1

帖子 schspa » 2013-08-20 13:49

代码: 全选

#!/bin/bash

#used to mount a iso image file to /media
echo please input your iso file path and name
echo And between the path and name ,type a "' '""<space>"
if [ "$1"x = ""x ]|| [ "$2"x = ""x ]
then
        echo '$1' = $1
        echo '$2' = $2
        echo check out '$1' and '$2' 
        exit 1
fi

if [ -f $1$2 ]
then
        echo iso image file do exists..
else
        echo "iso image file '$1$2'  don't exists.."
        exit 1
fi

filename=$2
echo $filename
echo make a file to mount the iso image
echo ${filename%%.iso}
sudo mkdir -p /mnt/${filename%%.iso}
sudo mount -o loop $1$2 /mnt/${filename%%.iso}
exit 0
这个可以正常工作,不过我有问题:
schspa@schspa-Laptop:~/桌面/programming/shell$ ./mount_iso.sh /media/schspa/exp/systemimage/ ubuntu-13.04-desktop-amd64.iso
please input your iso file path and name
And between the path and name ,type a ' '<space>
iso image file do exists..
ubuntu-13.04-desktop-amd64.iso
make a file to mount the iso image
ubuntu-13.04-desktop-amd64
/bin/rm: 无法删除"/run/user/root/gvfs": 是一个目录
mount: warning: /mnt/ubuntu-13.04-desktop-amd64 seems to be mounted read-only.
/bin/rm: 无法删除"/run/user/root/gvfs": 是一个目录
不知道问什么会有这个输出,求大神。是脚本的问题吗??
/bin/rm: 无法删除"/run/user/root/gvfs": 是一个目录


另外mount_iso.sh /media/schspa/exp/systemimage/ubuntu-13.04-desktop-amd64.iso
这种字符串怎么吧后边的ubuntu-13.04-desktop-amd64.iso和路径/media/schspa/exp/systemimage提取出来??
得意不忘形,失意不变形。。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 晒一下第一个脚本mount_iso.sh自动挂载iso文件

#2

帖子 eexpress » 2013-08-20 14:27

man basename
● 鸣学
头像
schspa
帖子: 49
注册时间: 2012-02-06 14:54
联系:

Re: 晒一下第一个脚本mount_iso.sh自动挂载iso文件

#3

帖子 schspa » 2013-08-21 8:35

eexpress 写了:man basename
fine ,thanks..
得意不忘形,失意不变形。。
回复