首页 > 其他分享 >bash exercise

bash exercise

时间:2023-02-17 18:44:15浏览次数:36  
标签:name array echo exercise subscript expands declare bash

3.5.2 Tilde Expansion


echo "~"       # only begin with an unquoted character is considered a tilde-prefix
echo ~
touch t.txt
ls ~+/t.txt      # use the shell variable PWD replaces the tilde-prefix
mkdir td
cd td
ls ~-/t.txt      # use the OLDPWD variable replaces the tilde-prefix

3.5.3 Shell Parameter Expansion

3.7 Arrays

$ declare -a array               		# declare a indexed array
declare -a arr[2]                       # 2 is ignored
$ echo ${array[@]} 						# all members of the array name
array=([0]=2 [1]=3)  				    # the form [subscript]=string .
$ echo ${array[*]}                      # 
array=(2 3 4 5 6)					    # index array do not require anything but string
IFS=","                                 # set IFS
echo "${array[*]}"   					# expands to a single word with the value of each array member separated by the first character of the IFS varaible
echo "${array[@]}"                      # expands each element of name to a separated word.
echo ${#{array[@]}                      #expands to the length of ${name[subscript]}
echo ${array[-2]}                       # intepreted ass relative to one greater than the maximum index of name 
echo ${array}  							# Referencing an array varaible without a subscript is equivalent with a subscript of 0 
echo ${noexist[2]} 						#  Any reference to a variable using a valid subscript is legal, and bash will create an array if necessary.
echo ${!array[@]}  						# obtain the keys of an array 
echo ${!array[*]}  						# the same to @
unset array[0]   						# destroy the array element  
unset array     						# destroy arrays



$ declare -A Array 						# declare a associative array
Array[a]=123					 		#using the [subscript]=value to assign a value 
Array+=([c]=7 [d]=8)             		# use the operator+ 

declare -aA arrOrArr  					# -A takes precedence

read -a stdarr   						#  assign a list of words read from the standard input to an array.

filename expands

标签:name,array,echo,exercise,subscript,expands,declare,bash
From: https://www.cnblogs.com/ysjblog/p/17131221.html

相关文章

  • bash eval
    eval_tutorialspinteval[arg...]EvalcommandcanexecutethancommandstoredinthestringExample#example1$COMMAND="ls-lrt"$eval$COMMAND#example2......
  • -bash: pip: command not found
    使用pip安装软件包时报错命令不存在[root@test~]#pip-V-bash:pip:commandnotfound 机器上没有安装pip,需要手动进行安装centos系统:#python3.7版本wgetht......
  • git bash窗口创建vue项目, 箭头切换没起作用?
    1、解决方法:一、直接在命令窗口创建(Win+R),输入cmd二、使用winpty命令+.cmd,如:winptynpm.cmdcreatevite@latest  ......
  • 论.bashrc和.bash_profile的区别
    背景今天在使用堡垒机连接后端主机的时候发现无法使用xftp打开后端主机的/tmp目录,但是用ssh命令行登陆可以列出/tmp目录,折腾了快一天了才发现问题原因,原来是自己的基础不牢......
  • linux 基础(6)简单认识 bash
    shell和bash是什么?shell是一种应用程序,在这个程序里输入文字指令,系统就会做出响应的操作。这个“壳程序”是我们使用系统各种功能的接口,学会了shell就是学会操作li......
  • 分享一些超有用的BASH命令
    调出CMD界面(Win+R,输入cmd,回车)    1.查看所有该电脑连接过的WIFI密码信息for/f"skip=9tokens=1,2delims=:"%iin('netshwlanshowprofiles')do@echo......
  • Two Exercises of Gramian
    目录TwoExercisesofGramian"Gramiandeterminesshape""Almostorthonormal"TwoExercisesofGramian"Gramiandeterminesshape"Proposition.Let\(\{v_1,\cdots,......
  • 让 MSYS2 Bash 像 Git Bash 一样显示 Git 分支名称
    GitforWindows的Bash有一个很实用的功能,如果当前目录处于Git仓库中,那么命令行中会显示当前Git分支的名称(见下图)。然而原版的MSYS2Bash没有这个功能(见下图),不......
  • [Postgres Bash] Wait for database
    Serverwaitfordatabasegetready#Fromhttps://docs.docker.com/compose/startup-order/#!/bin/sh#wait-for-postgres.shset-ehost="$1"shift#Logi......
  • Go Linux bash环境下 字符串strings.Trim截取无效
    result:="40%"iflen(result)>0{fmt.Println("result:",result)numStr:=strings.TrimSpace(strings.Trim(result,"%"))fmt......