1: Setting Variables (Working with programs)

本文介绍了如何通过Bash命令行与计算机交互的基础知识。Bash是最流行的命令行Shell之一,广泛应用于Linux和OSX系统中。文章讲解了Bash的基本概念、命令语言的结构,并演示了如何设置变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In these shell tutorials, we've been interacting with a computer through the command line. In order to interact with it, we type commands in, those commands are executed, and we're shown the results. That interaction is happening within a shell called bash. A shell is a way to access and control a computer. Command line shells have a text interface for typing commands and seeing results, versus graphical shells which allow you to click on icons with a mouse. There are many unix shells, but Bash is one of the most popular. Bash is the default shell on most Linux and OSX computers.

Bash is essentially a program that lets us run other programs. To do this, Bash implements a command language. This language specifies how we can type and structure commands that will be executed. A command language is a special kind of programming language through which we can control applications and the system. Just like other programming languages, like Python, we can create scripts, set variables, and more. Because it is a language, bash is far more powerful than a graphical shell.

We can set variables by assigning to them. Variables consist entirely of uppercase characters, numbers, and underscores. You can assign any datatype to a variable. Here are some examples:

 

OS=linux

OPERATING_SYSTEM="linux"

Both of the above variables OS andOPERATING_SYSTEM will actually be assigned the same value. Quotes are optional when using strings in bash, unless there's a space in the string -- bash is sensitive to spaces, and strings with spaces won't work properly if they aren't surrounded with quotes.

This assignment won't work:

 

ANIMAL=Shark with a laser beam on its head

But this will:

 

ANIMAL="Shark with a laser beam on its head"

It's also important not to add in stray spaces. This won't work:

 

ANIMAL = "Shark with a laser beam on its

    head"

Instructions

  • Create a variable FOOD containing the value Shrimp gumbo

转载于:https://my.oschina.net/Bettyty/blog/746499

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值