Seeing The World As The Shell Sees It

2024-04-20 09:38
文章标签 shell world seeing sees

本文主要是介绍Seeing The World As The Shell Sees It,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Here we will introduce one command:
echo:display a line of text

Expansion

For example “*”,can have a lot of meaning to the shell.The process that makes this happen is called expansion.

echo

echo is a shell built that performs a very simple task.example:

echo this is a text
echo *

can’t print ““,in privious character means match any characters in a filename.The shell expanse the “*” into something else before the echo command is executed.When the enter key is pressed,the shell expands any qualifying characters on the command line before the command is carried out.example:

echo [[:upper:]]*
## will show all the file that beginning with an upper character
echo /usr/*/share
## "*" expanse everything you can image~

want to expanse hiden file?,OK:

echo .*

but this command will show ‘.’ and ‘..’ this two.If I don’t want show current directory and parent directory,I can try:

echo .[!.]*

this will work correctly in most files.It still can’t include filenames with multiple leading periods,so if you want to show a correct listing of hidden files:

ls -A

Tilde Expansion

the ~ character means the home directory of the current user:

echo ~

if user ‘wuxiao’ has an account,then:

echo ~wuxiao
## it is the same of 'echo ~' with 'wuxiao' user

Arithmetic Expansion

we can use the shell prompt as a calculator

echo $((2+2))

Arithmetic expansion use the form:

$((expression))

Arithmetic operators:
- +
- -
- *
- /
- ** :Exponentiation
example:

echo $(($((5**2))*3))
echo $((5**2*3))
echo $(((5**2)*3))
##output is 75
echo ((5/2))
##will display 2

Brace expansion

with brace,you can create multiple text strings from a pattern containing braces,example:

echo Front - {A,B,C} - Back
## will show  'Front - {A,B,C} - Back'

using a range of integers:

echo Number_{1..5}
##will show Number_1 Number_2 ... Number_5

also can be zero-padded like:

echo {001..6}
##001 002 003 ... 006
echo {z..a}
##z y x ... a

The most common application is to make lists of files or directories to be created:

mkdir {2015..2017}-{01..12}

Parameter expansion

Use variable to store small chunks of data and to give each chunk a name.

echo $USER
printenv | less
echo $(ls)

Quoting

echo this is a                       test
##this is a test
echo the total is $100.00
##the total is 00.00

Shell will remove the extra whitespace from the echo command’s arguments.example 2 shell will treat ‘$1’ as a parameter expasion.SO what should we do if we want to leave the origin output?

Use Double Quotes

ls -l "two words.txt"
mv "two words.txt" two_words.txt
echo "$USER "\$100.00" $(cal)"

Single Quotes

If we need to suppress all expansions,we use single quotes:

echo '23467567*&!~@$%}{}|?/\6346'

Escaping Characters ‘\’

Just like the function in C.Here are some frequent examples:
- \a:Bell
- \b:Backspace
- \n:NewLine
- \r:Carriage return
- \t:Tab

这篇关于Seeing The World As The Shell Sees It的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/919902

相关文章

Linux中shell解析脚本的通配符、元字符、转义符说明

《Linux中shell解析脚本的通配符、元字符、转义符说明》:本文主要介绍shell通配符、元字符、转义符以及shell解析脚本的过程,通配符用于路径扩展,元字符用于多命令分割,转义符用于将特殊... 目录一、linux shell通配符(wildcard)二、shell元字符(特殊字符 Meta)三、s

shell脚本快速检查192.168.1网段ip是否在用的方法

《shell脚本快速检查192.168.1网段ip是否在用的方法》该Shell脚本通过并发ping命令检查192.168.1网段中哪些IP地址正在使用,脚本定义了网络段、超时时间和并行扫描数量,并使用... 目录脚本:检查 192.168.1 网段 IP 是否在用脚本说明使用方法示例输出优化建议总结检查 1

jenkins 插件执行shell命令时,提示“Command not found”处理方法

首先提示找不到“Command not found,可能我们第一反应是查看目标机器是否已支持该命令,不过如果相信能找到这里来的朋友估计遇到的跟我一样,其实目标机器是没有问题的通过一些远程工具执行shell命令是可以执行。奇怪的就是通过jenkinsSSH插件无法执行,经一番折腾各种搜索发现是jenkins没有加载/etc/profile导致。 【解决办法】: 需要在jenkins调用shell脚

站长常用Shell脚本整理分享(全)

站长常用Shell脚本整理分享 站长常用Shell脚本整理分享1-10 站长常用Shell脚本整理分享11-20 站长常用Shell脚本整理分享21-30 站长常用Shell脚本整理分享31-40 站长常用Shell脚本整理分享41-50 站长常用Shell脚本整理分享51-59 长期更新

Shell脚本实现自动登录服务器

1.登录脚本 login_server.sh #!/bin/bash# ReferenceLink:https://yq.aliyun.com/articles/516347#show all host infos of serverList.txtif [[ -f ./serverList.txt ]]thenhostNum=`cat ./serverList.txt | wc -l`e

[轻笔记]ubuntu shell脚本切换conda环境

source /home/yourhostname/anaconda3/etc/profile.d/conda.sh # 关键!!!conda activate env_name

[轻笔记] ubuntu Shell脚本实现监视指定进程的运行状态,并能在程序崩溃后重启动该程序

根据网上博客实现,发现只能监测进程离线,然后对其进行重启;然而,脚本无法打印程序正常状态的信息。自己通过不断修改测试,发现问题主要在重启程序的命令上(需要让重启的程序在后台运行,不然会影响监视脚本进程,使其无法正常工作)。具体程序如下: #!/bin/bashwhile [ 1 ] ; dosleep 3if [ $(ps -ef|grep exe_name|grep -v grep|

adb shell 执行后台程序后断开adb后台进程被结束的解决办法

环境:Android 版本 Android8 通常让程序后台执行就是在命令 最后加上 &即可,但是在Android 8上实验发现,程序的确后台了,但是拔掉USB线再连接上发现进程已结束。不确定Android早期版本是否存在此问题。 参考网上一些Linux方法,如加nohup 仍然无效,还是会结束。看来Android adb shell 与 Linux shell 还是有一定区别。 后来在网上

shell脚本中变量中字符串替换的测试 /和//的区别

test_char=abbbcbbbf echo "bf:test_char = " $test_char test_char=${test_char/bbb/ddd} echo "af:test_char = " $test_char 输出: bf:test_char =  abbbcbbbf af:test_char =  adddcbbbf 只匹配第一个