MacOS write a fun and useful shell script

As a developer, without end operation, then can macOS systems, like the Windows system, store the terminal instructions into executable files?
answer: Yes, but a little different.
first give you a simple example: create text documents, modify the suffix called.Sh, use Notepad (Xcode, or other professional software) to open, add the following code, you can save it.

MacOS write a fun and useful shell script
, a simple script


那么,怎么运行这个脚本呢?

答:有两种方式。

第一种方式:打开终端,使用Bash script path,直接打开。

MacOS write a fun and useful shell script
, the first way


第二种方式:打开终端,先开启文件的可执行权限Chmod +x script path

修改之后,每次打开都可以Drag files directly to the terminalEnter即可implement

MacOS write a fun and useful shell script,
, second ways


Whimsy: create a local code uploaded to the remote shell script.

作为一个开发者,少不了Code management,每一个项目,首次将代码上传至远程仓库的时候,都要输入一大堆git命令,那么能不能将这些git命令Encapsulated into a shell script,直接执行呢?

答:能,并且简单高效。

先把代码粘贴出来:

#! /bin/bash (ll_git) init touch README.md git {git add README.md echo -n "remote input link address:" read remoteUrl git remote add origin $remoteUrl git add git commit -m. If the "Initial commit" git push origin master --force echo} "use the simple operation? (y/n)" read isShortcut if "=" $isShortcut "Y"; then echo "input file (folder) Directory: path CD $path currentDic=$read (PWD) if" $path = $currentDic "; then ll_git else echo" file directory failed, please manually switch to the directory folder and choose the "non simple:" fi else ll_git fi

The implementation effect is as follows:

MacOS write a fun and useful shell script
uses shell scripts to submit code to remote repositories


当然,这些只是最基本的脚本应用,还有很多好玩的功能等着大家开发,如果有童鞋对脚本语言感兴趣,不妨看看下面两篇文章,写的很好。

Scripting language syntax rules

A good tutorial for shell scripts

Feel good, please give a star, thank you!