南京小程序开发,南京H5,南京公众号开发,南京网站建设,南京网站制作,南京网站设计,南京做网站,南京网站开发,南京网站建设公司,南京网站制作公司,南京网站设计公司
-->

电话:

400-885-7836

微信:

南京小程序开发,南京H5,南京公众号开发,南京网站建设,南京网站制作,南京网站设计,南京做网站,南京网站开发,南京网站建设公司,南京网站制作公司,南京网站设计公司

商务QQ:

923368187

南京小程序开发,南京H5,南京公众号开发,南京网站建设,南京网站制作,南京网站设计,南京做网站,南京网站开发,南京网站建设公司,南京网站制作公司,南京网站设计公司

联系我们

Slide
无需任何编程和设计经验,用户可在3分钟之内快速创建小程序,最快5分钟微信审核通过上线

操作步骤: 扫码登录 -> 创建店铺 -> 授权小程序 -> 选择适合的模板 -> 体验码体验 -> 发布小程序

当前位置:首页 > mac相关 > 如何创建一个Mac,Unix Bash脚本

所有分类

如何创建一个Mac,Unix Bash脚本

The ability to create and make your own custom bash scripts is on of the biggest advantages to working off a unix based operating system (like the mac).

You can take just about any mundane, or complicated task, and easily automated it by learning how to create your own bash scripts.

In this post I am going to show you how to create a bash script called:

findtext.sh

(which recursively search all files for text containing xxx (very handy)) and call it from anywhere on your computer.

Setup your environment

Go to your home directory:

$ cd ~

and make a directory called scripts (this is where you will store your scripts):

$ mkdir scripts

Then if you don’t have one already, create a .bash_profile file (in your root directory) and add the following line:

export PATH=$PATH:~/scripts

This puts the directory you just created into the unix $PATH variable which lets you call your scripts from anywhere on your machine.

To register this new path you may need to go:

$ source .bash_profile

You can then check your new path by typing:

$ echo $PATH
/opt/local/bin:...:/usr/local/bin:/usr/X11/bin:/Users/jr/scripts

If all is well you should see your new directory in the output.

OK. We are now ready to create your script.

Create your script

To create your script go back to that scripts directory your just created and using your favorite text editor create a file called ‘findtext.sh’

#!/bin/bash
echo "Searching for text:" $1
find . -type f -exec grep -il $1 {} \;

And give yourself permission to execute it using the following command:

$ chmod 711 findtext.sh

That’s it! At this point you are basically done.

You should now be able to run this script from anywhere on your box.

To test it out, navigate to some directory containing a lot of files and text and search for something.

Here is the output I get when I search my rails app for ‘README’

$ findtext.sh README
Searching for text: README
./testApp/doc/README_FOR_APP
./testApp/generate/doc/README_FOR_APP
./testApp/generate/README

Add your aliases

You can also add aliases to your .bash_profile to help make your life easier.

alias dev='cd /Users/jr/Documents/dev/rails'

Now I can type ‘dev’ and instant be taken to my development directory.

易企达10年行业沉淀!专业小程序、公众号H5、APP定制开发
拨打电话立享优惠

400-885-7836

点击获取报价

本文原地址:https://www.eqiday.com/101.html
郑重声明内容版权声明:除非注明,否则皆为本站原创文章。如有侵权联系进行删除!

无需任何编程和设计经验,用户可在10分钟之内快速创建小程序,所有功能免费!

操作步骤: 注册 -> 登录 -> 创建店铺 -> 授权小程序 -> 上传代码 -> 生成体验码体验 -> 发布小程序

免费制作小程序