avi@tecmint:~$ /bin/pwd --version
pwd (GNU coreutils) 8.23
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jim Meyering.
15. 写一个shell脚本分析home目录下的一个目录(比如tecmint)。如果当前目录是tecmint就输出“Well! You are in tecmint directory”接着输出“Good Bye”,不然就在tecmint下面创建一个目录并提示你cd进入它。
让我们首先创建一个‘tecmint’目录,在下面创建一个名为‘pwd.sh’的脚本文件。
代码如下:
avi@tecmint:~$ mkdir tecmint
avi@tecmint:~$ cd tecmint
avi@tecmint:~$ nano pwd.sh
接下来在pwd.sh中加入下面的脚本。
代码如下:
#!/bin/bash
x="$(pwd)"
if [ "$x" == "/home/$USER/tecmint" ]
then
{
echo "Well you are in tecmint directory"
echo "Good Bye"
}
else
{
mkdir /home/$USER/tecmint
echo "Created Directory tecmint you may now cd to it"
}
fi
给予执行权限并运行。
代码如下:
avi@tecmint:~$ chmod 755 pwd.sh
avi@tecmint:~$ ./pwd.sh
Well you are in tecmint directory
Good Bye