在Shell脚本里操作指令:如何在编写脚本时执行命令 - 功能定义详解
最编程
2024-07-25 19:11:17
...
Users can define their own functions in a script. These functions can take multiple arguments.
用户可以在脚本中定义自己的功能。 这些函数可以采用多个参数。
In the script add :
在脚本中添加:
#!/bin/bash
#This is a comment
#defining a variable
echo "What is the name of the directory you want to create?"
#reading input
read NAME
#defining a variable
echo "Creating $NAME ..."
mkcd ()
{
mkdir "$NAME"
cd "$NAME"
}
mkcd
echo "You are now in $NAME"
This script will ask the user for a directory name. It will then create the directory and cd into it.
该脚本将询问用户目录名称。 然后它将创建目录并cd进入该目录。