在PATH中显示目录,每行一个

这在bash中不起作用,但在zsh中,您可以排版-T将标量变量绑定到数组。默认情况下,$ PATH和$ path的行为方式如此。
.

0

linux命令:print -l $path $path -l print print -l $pathrootopen.com
linux命令:print -l $path $path -l print print -l $pathrootopen.com
zwea 2018-04-11 03:03:48
输出
替代方案1 在PATH中显示目录,每行一个

quoteless.

linux命令:echo -e ${PATH//:/\\n} ${PATH//:/\\n} -e echo echo -e ${PATH//:/\\n}rootopen.com
linux命令:echo -e ${PATH//:/\\n} ${PATH//:/\\n} -e echo echo -e ${PATH//:/\\n}rootopen.com
.
输出
替代方案2 在PATH中显示目录,每行一个

删除后面的换行符;冒号成为记录分隔符,换行成为字段分隔符,只打印第一个字段。用$ PWD替换空的条目。还要在当前目录($ PWD)前加上相关目录(如“。”)。可以使用env(1)更改PWD以在(非Bourne)脚本中变得棘手。.

linux命令:echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print $1}' $1}' 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print awk | src::${PATH} echo echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print $1}'rootopen.com
linux命令:echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print $1}' $1}' 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print awk | src::${PATH} echo echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print $1}'rootopen.com
.
输出
替代方案3 在PATH中显示目录,每行一个

这个版本使用Pipes,但对于普通用户来说更容易掌握...而不是使用sed或其他更复杂的方法,它使用tr命令.

linux命令:echo $PATH | tr \: \\n \\n \: tr | $PATH echo echo $PATH | tr \: \\nrootopen.com
linux命令:echo $PATH | tr \: \\n \\n \: tr | $PATH echo echo $PATH | tr \: \\nrootopen.com
.
输出
替代方案4 在PATH中显示目录,每行一个

更短的版本。.

linux命令:echo "${PATH//:/$'\n'}" "${PATH//:/$'\n'}" echo echo "${PATH//:/$'\n'}"rootopen.com
linux命令:echo "${PATH//:/$'\n'}" "${PATH//:/$'\n'}" echo echo "${PATH//:/$'\n'}"rootopen.com
.
输出
替代方案5 在PATH中显示目录,每行一个

“echo $ PATH”的输出很难阅读,这很容易。括号确保对输入字段分隔符(IFS)的更改仅发生在子shell中,并且不会影响当前shell。.

linux命令:( IFS=:; for p in $PATH; do echo $p; done ) ) done $p; echo do $PATH; in p for IFS=:; ( ( IFS=:; for p in $PATH; do echo $p; done )rootopen.com
linux命令:( IFS=:; for p in $PATH; do echo $p; done ) ) done $p; echo do $PATH; in p for IFS=:; ( ( IFS=:; for p in $PATH; do echo $p; done )rootopen.com
.
输出

评论

相关推荐

通过从procfs读取来检查是否在系统范围内启用了IPv6。

linux命令:printf "IPv6 is "; [ $(cat /proc/sys/net/ipv6/conf/all/disable_ipv6) -eq 0 ] && printf "enabled\n" || printf "disabled\n" "disabled\n" printf || "enabled\n" printf && ] 0 -eq /proc/sys/net/ipv6/conf/all/disable_ipv6) $(cat [ "; is "IPv6 printf printf "IPv6 is "; [ $(cat /proc/sys/net/ipv6/conf/all/disable_ipv6) -eq 0 ] && printf "enabled\n" || printf "disabled\n"rootopen.com
linux命令:printf "IPv6 is "; [ $(cat /proc/sys/net/ipv6/conf/all/disable_ipv6) -eq 0 ] && printf "enabled\n" || printf "disabled\n" "disabled\n" printf || "enabled\n" printf && ] 0 -eq /proc/sys/net/ipv6/conf/all/disable_ipv6) $(cat [ "; is "IPv6 printf printf "IPv6 is "; [ $(cat /proc/sys/net/ipv6/conf/all/disable_ipv6) -eq 0 ] && printf "enabled\n" || printf "disabled\n"rootopen.com
.

linux命令:printf -v _hr "%*s" $(tput cols) && echo ${_hr// /${1--}} /${1--}} ${_hr// echo && cols) $(tput "%*s" _hr -v printf printf -v _hr "%*s" $(tput cols) && echo ${_hr// /${1--}}rootopen.com
linux命令:printf -v _hr "%*s" $(tput cols) && echo ${_hr// /${1--}} /${1--}} ${_hr// echo && cols) $(tput "%*s" _hr -v printf printf -v _hr "%*s" $(tput cols) && echo ${_hr// /${1--}}rootopen.com
.

将下划线'_'替换为任何其他字符.例如+或 - 或=

linux命令:printf "%`tput cols`s"|sed "s/ /_/g" /_/g" "s/ cols`s"|sed "%`tput printf printf "%`tput cols`s"|sed "s/ /_/g"rootopen.com
linux命令:printf "%`tput cols`s"|sed "s/ /_/g" /_/g" "s/ cols`s"|sed "%`tput printf printf "%`tput cols`s"|sed "s/ /_/g"rootopen.com
.

linux命令:printenv SHELL SHELL printenv printenv SHELLrootopen.com
linux命令:printenv SHELL SHELL printenv printenv SHELLrootopen.com
.

在默认状态下,它们应该完全相同

linux命令:printenv printenv printenvrootopen.com
linux命令:printenv printenv printenvrootopen.com
.

以satoshis / Byte,sat / B,日期时间戳紧凑显示比特币价值估算。将6更改为所需的确认数。以btc / KB测量单位显示: printf %g "$(bccli estimatesmartfee 6 "ECONOMICAL" | jq .feerate)";printf " btc/KB estimated feerate for 6 confirmations\nMultiply by 100,000 to get sat/B\n"; 估算模式的两个设置是“ECONOMICAL”。“CONSERVATIVE”与“UNSET”相同#jq是json过滤器。 sudo apt-get install jq

linux命令:printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n" btc/KB\n" get to 100,000 by +%c)\nDivide $(date of as confirmations 6 for feerate estimated sat/B " .feerate*100000)";printf jq | "ECONOMICAL" 6 estimatesmartfee "$(bitcoin-cli %g printf printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n"rootopen.com
linux命令:printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n" btc/KB\n" get to 100,000 by +%c)\nDivide $(date of as confirmations 6 for feerate estimated sat/B " .feerate*100000)";printf jq | "ECONOMICAL" 6 estimatesmartfee "$(bitcoin-cli %g printf printf %g "$(bitcoin-cli estimatesmartfee 6 "ECONOMICAL" | jq .feerate*100000)";printf " sat/B estimated feerate for 6 confirmations as of $(date +%c)\nDivide by 100,000 to get btc/KB\n"rootopen.com
.

有时,在shell脚本中,您需要一个大于$ RANDOM范围的随机数。这将打印一个由/ dev / urandom提取的四个十六进制值组成的随机数。

linux命令:printf %d 0x`dd if=/dev/urandom bs=1 count=4 2>/dev/null | od -x | awk 'NR==1 {print $2$3}'` $2$3}'` {print 'NR==1 awk | -x od | 2>/dev/null count=4 bs=1 if=/dev/urandom 0x`dd %d printf printf %d 0x`dd if=/dev/urandom bs=1 count=4 2>/dev/null | od -x | awk 'NR==1 {print $2$3}'`rootopen.com
linux命令:printf %d 0x`dd if=/dev/urandom bs=1 count=4 2>/dev/null | od -x | awk 'NR==1 {print $2$3}'` $2$3}'` {print 'NR==1 awk | -x od | 2>/dev/null count=4 bs=1 if=/dev/urandom 0x`dd %d printf printf %d 0x`dd if=/dev/urandom bs=1 count=4 2>/dev/null | od -x | awk 'NR==1 {print $2$3}'`rootopen.com
.

假设你想用bash / zsh命令行编辑来编辑你的PATH变量,这会在历史中放入类似这样的东西,以便编辑它:PATH = / bin:/ usr / bin:/ usr / sbinto使shell成为shell函数:eev首页将在最后的历史事件中放置/ home / dave:eev(){print -s“$ 1 ='$(eval echo \ $$ 1)'”}

linux命令:print -s "PATH='$PATH'" "PATH='$PATH'" -s print print -s "PATH='$PATH'"rootopen.com
linux命令:print -s "PATH='$PATH'" "PATH='$PATH'" -s print print -s "PATH='$PATH'"rootopen.com
.

如果您曾经想更改文本文件内容而无需创建中间文件。就是这个。 Ex是vim的一部分。更多示例:print'%s /'这是一行'/',它不是同一行'/ g \ nwq'| ex file.txt会将第一个字符串替换为第二个字符串。打印'3a \ n'Inserted Line'\ n。\ n \ nwq'| ex file.txt会在第3行后面插入给定的行.CAVEAT,有些发行版像打印命令,其他发行版像这个命令一样回显。还要注意,没有失败的错误消息,至少我见过。 Ex对于如何使用字符串,参数等也很麻烦......我在&t的ksh语法中使用的可能与其他shell很相似。

linux命令:print 'g/'delete this line'/delete\nwq' | ex file.txt file.txt ex | line'/delete\nwq' this 'g/'delete print print 'g/'delete this line'/delete\nwq' | ex file.txtrootopen.com
linux命令:print 'g/'delete this line'/delete\nwq' | ex file.txt file.txt ex | line'/delete\nwq' this 'g/'delete print print 'g/'delete this line'/delete\nwq' | ex file.txtrootopen.com
.

我使用它作为别名:alias authplain“printf'\ !: 1 \ 0 \ !: 1 \ 0 \ !: 2'| mmencode | tr -d'\ n'| sed's / ^ / AUTH PLAIN /' “然后..#authplain someuser@somedomain.com secretpasswordAUTH PLAIN c29tZXVzZXJAc29tZWRvbWFpbi5jb20Ac29tZXVzZXJAc29tZWRvbWFpbi5jb20Ac2VjcmV0cGFzc3dvcmQ =#

linux命令:printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /' /' PLAIN 's/^/AUTH sed | '\n' -d tr | mmencode | '\!:1\0\!:1\0\!:2' printf printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'rootopen.com
linux命令:printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /' /' PLAIN 's/^/AUTH sed | '\n' -d tr | mmencode | '\!:1\0\!:1\0\!:2' printf printf '\!:1\0\!:1\0\!:2' | mmencode | tr -d '\n' | sed 's/^/AUTH PLAIN /'rootopen.com
.

它不适用于Cygwin的bash3.X。在Linux中测试。使用printf“%f”号码,而它是浮点数

linux命令:printf "%'d\n" 1234567 1234567 "%'d\n" printf printf "%'d\n" 1234567rootopen.com
linux命令:printf "%'d\n" 1234567 1234567 "%'d\n" printf printf "%'d\n" 1234567rootopen.com
.

linux命令:printf '%*s\n' 20 | tr ' ' '#' '#' ' ' tr | 20 '%*s\n' printf printf '%*s\n' 20 | tr ' ' '#'rootopen.com
linux命令:printf '%*s\n' 20 | tr ' ' '#' '#' ' ' tr | 20 '%*s\n' printf printf '%*s\n' 20 | tr ' ' '#'rootopen.com
.

模拟bash 4的“echo {03..20}”使用函数printf中内置的bash 3

linux命令:printf "%02u " {3..20}; echo echo {3..20}; " "%02u printf printf "%02u " {3..20}; echorootopen.com
linux命令:printf "%02u " {3..20}; echo echo {3..20}; " "%02u printf printf "%02u " {3..20}; echorootopen.com
.

linux命令:printf "%d\n" "'A" "'B" "'B" "'A" "%d\n" printf printf "%d\n" "'A" "'B"rootopen.com
linux命令:printf "%d\n" "'A" "'B" "'B" "'A" "%d\n" printf printf "%d\n" "'A" "'B"rootopen.com
.

在大多数现代shell中,printf是一个内置命令。

linux命令:printf "%s\n" .* .* "%s\n" printf printf "%s\n" .*rootopen.com
linux命令:printf "%s\n" .* .* "%s\n" printf printf "%s\n" .*rootopen.com
.

linux命令:printf "%s\n" .* .* "%s\n" printf printf "%s\n" .*rootopen.com
linux命令:printf "%s\n" .* .* "%s\n" printf printf "%s\n" .*rootopen.com
.

linux命令:printf "%s\n" ${PATH//:/\/* } } ${PATH//:/\/* "%s\n" printf printf "%s\n" ${PATH//:/\/* }rootopen.com
linux命令:printf "%s\n" ${PATH//:/\/* } } ${PATH//:/\/* "%s\n" printf printf "%s\n" ${PATH//:/\/* }rootopen.com
.

我的版本使用printf和命令替换($())而不是echo -e和xargs,这是一些较少的字符,但不是真正的实质性区别。还支持小写的十六进制字母和反斜杠(\)将使它通过未转义

linux命令:printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g') 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g') sed | $1 -n $(echo printf printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')rootopen.com
linux命令:printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g') 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g') sed | $1 -n $(echo printf printf $(echo -n $1 | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')rootopen.com
.

不需要ls或grep; printf是内置于大多数现代炮弹的

linux命令:printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglob extglob -s shopt with bash or ksh, ## !(pattern) "%s\n" printf printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglobrootopen.com
linux命令:printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglob extglob -s shopt with bash or ksh, ## !(pattern) "%s\n" printf printf "%s\n" !(pattern) ## ksh, or bash with shopt -s extglobrootopen.com
.

将70替换为所需的高度。用所需的宽度替换180.我把它放在我的bashrc中,因为默认情况下我的终端太小了。

linux命令:printf "\e[8;70;180;t" "\e[8;70;180;t" printf printf "\e[8;70;180;t"rootopen.com
linux命令:printf "\e[8;70;180;t" "\e[8;70;180;t" printf printf "\e[8;70;180;t"rootopen.com
.
共收录0条命令行
这里是记录和分享命令行的地方, 所有命令行都可以进行评论、提交替代方案.

推荐
    热门命令