macos 运行linux,MacOS 上运行shell
### 什么是shell脚本?
##### Wikipedia:
> In [computing](https://link.jianshu.com?t=https://en.wikipedia.org/wiki/Computing), a **shell** is a [user interface](https://link.jianshu.com?t=https://en.wikipedia.org/wiki/User_interface) for access to an [operating system](https://link.jianshu.com?t=https://en.wikipedia.org/wiki/Operating_system)'s services. In general, operating system shells use either a [command-line interface](https://link.jianshu.com?t=https://en.wikipedia.org/wiki/Command-line_interface) (CLI) or [graphical user interface](https://link.jianshu.com?t=https://en.wikipedia.org/wiki/Graphical_user_interface) (GUI), depending on a computer's role and particular operation.
### 一个简单的shell脚本例子
> 创建一个helloworld.sh
```
#!/bin/bash
echo "hello world"
```
> 在终端下运行(以下几种方式都可以)
```
. helloworld.sh
```
```
source helloworld.sh
```
```
bash helloworld.sh
```
> 输出
```
hello world
```
### 语法解释
------
##### 1. 指定命令解释器
```
#!/bin/bash
```
- 这句只能放在第一行
- \#! 指示解释此脚本的shell命令解释器
- /bin/bash 指代的是bash命令解释器
- 若要双击执行,用chmod修改文件属性
```
#给当前用户的file文件添加可执行权限
chmod u+x file
```
------
##### 2. 执行脚本
```
. helloworld.sh
```
```
source helloworld.sh
```
> A dot in that context means to "source" the contents of that file into the current shell. With [source](https://link.jianshu.com?t=http://ss64.com/bash/source.html) itself being a shell builtin command. And source and the dot operator being synonyms.
------
### 附
#### bash与sh的区别
> `bash`
> `Bourne Again Shell`是linux标准的默认shell,它基于Bourne shell,吸收了C shell和Korn shell的一些特性。bash完全兼容Bourne shell, 也就是说用Bourne shell的脚本不加修改就可以在bash中执行。
> `sh`
> `Bourne shell`是UNIX标准的默认shell,对它评价是:简洁(concise)、紧凑(compact) 、快速(fast),它由AT&T编写,属于系统管理shell。
>
`bash` and `sh` are two different shells. Basically `bash` is `sh`, with more features and better syntax. Most commands work the same, but they are different.
***
# 参考资料
- ZhengHuaxing:编程基础#如何在OS X下创建并运行一个shell脚本
https://www.jianshu.com/p/60d240383180
macos 运行linux,MacOS 上运行shell相关推荐
- Java程序部署到Linux环境上运行
文章目录 前言 一.Java环境安装 二.Eclipse编译java程序并导出jar包 三.Linux环境上运行jar包 前言 想要在Linux上运行java程序,可以将java程序编译成功后导出成j ...
- 服务器如何运行java文件_在linux服务器上运行java文件
1. 在windows环境下编写java类,如java类是Test类. 2. 将该Test类上传到linux服务器上,命令如下: mapred@10:/bwdata168_2/hyg$rz -b ...
- linux如何查看jupyter日志_在Linux服务器上运行Jupyter notebook server教程
在Linux服务器上运行Jupyter notebook server教程 很多deep learning教程都推荐在jupyter notebook运行python代码,方便及时交互.但只在本地运行 ...
- anbox 使用情况_Anbox让您在Linux桌面上运行Android应用程序
Anbox让您在Linux桌面上运行Android应用程序 imcn 2017年4月13日 1条评论 阅读 18,083 次 认识一下Anbox,一种新颖的在Linux桌面上运行Android应用的新 ...
- 如何检查Linux系统上运行的Debian版本
转载来源:https://linuxconfig.org/check-what-debian-version-you-are-running-on-your-linux-system 检查Linux系 ...
- win10应用开发——如何判断应用是在手机上运行还是电脑上运行
原文:win10应用开发--如何判断应用是在手机上运行还是电脑上运行 在进行uwp应用开发的时候, 有时我们需要知道自己的应用是在手机端运行还是在桌面端运行,那么通过以下的api就可以进行判断: Wi ...
- 修改了xml要不要重新起服务器,关于设置:Eclipse每次运行项目时都会修改server.xml(运行-在服务器上运行)...
我在Eclipse Juno上使用Tomcat 7. 我使用工作区元数据作为服务器位置(请在下面查看我的tomcat配置). 另外,我在Eclipse中有一个Server项目[请参见下图],其中包含单 ...
- 如何快速查看Linux系统上的Shell类型
要快速查看Linux系统上的Shell类型,可以参考本经验以下内容. 一.查看当前系统中所有可登录shell的类型 1 要查看当前系统中所有可登录shell的类型,在/etc/shells配置文件中记 ...
- ps3运行linux,PS3上的PC系统Linux不是摆设!
当索尼首次宣布PlayStation3将能够直接运行Linux的时候,非常令人兴奋.最初,直接安装Linux会有些困难.PS3支持的安装程序运行自定义脚本,手工将FedoraCore5或6安装DVD改 ...
最新文章
- IE6,7,8,FF兼容总结
- 什么是 Design System
- 计算机网络第五章:运输层
- windows内核试验05_中断现场
- SpringBoot中使用 Druid 数据库连接池, 后台SQL监控无效
- 集成电路设计软件Tanner 16.30安装教程(附安装包)
- Rider 2021.3 Beta 现已推出
- Kneser猜想与相关推广
- 数据集蒸馏 by Matching Training Trajectories
- 工程监测管理平台、工程数据看板、工程总览、动态模型、数据分析、数据跟踪、建筑工地、数据报表、警点管控、现场记录、观测记录、测点管理、模型管理、文档管理、墙体下沉、成员管理、axure原型、产品原型
- 运行phpize时出现:Cannot find autoconf
- GPS广播星历和精密星历的下载
- 《数字图像处理》实验五
- Centos 7环境MySql8.0.28源码安装
- Codeforces 592 A. PawnChess 【Codeforces Round #328 (Div. 2)】
- 【Android进阶】(1)使用开源框架AndroidAnnotation
- Linux中的PS1变量
- 仿秒拍视频网UI主题模板+Emlog内核开发
- ETOKEN 身份认证 电子证书
- 3、按键扫描检测处理
热门文章
- ThinkPHP3快速入门教程二:数据CURD
- 晶振对stm32 串口数据传输的影响
- 从哪些角度进行手机软件测试
- Android 常用语句
- 在64位的 CentOS 上只安装64位的软件包
- OpenCV-最值计算cv::minMaxIdxcv::minMaxLoc
- android访问服务器405,android – HTTP状态405 – 不允许的方法(jax-rs服务)
- spring boot连接redis配置127.0.0.1_Java技术分享——Springboot整合redis
- Markdown插图片模板
- swift int转string_用Swift开发macOS程序,九、目录模块