可以$ {VAR}参数扩展前pressions被嵌套在bash? [英] Can ${var} parameter expansion expressions be nested in bash?

查看:143
本文介绍了可以$ {VAR}参数扩展前pressions被嵌套在bash?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经是这样的:

progname=${0%.*}
progname=${progname##*/}

这能嵌套(或没有)成一条线,即单次前pression?

Can this be nested (or not) into one line, i.e. a single expression?

我想,这样只有基本名称是留给剥离路径和扩展了脚本的名字。以上两行正常工作。我的'C'的性质仅仅是让我混淆这些甚至更多。

I'm trying to strip the path and extension off of a script name so that only the base name is left. The above two lines work fine. My 'C' nature is simply driving me to obfuscate these even more.

推荐答案

如果巢,你的意思是这样的:

If by nest, you mean something like this:

#!/bin/bash

export HELLO="HELLO"
export HELLOWORLD="Hello, world!"

echo ${${HELLO}WORLD}

然后不,你不能嵌套 $ {VAR} 前pressions。 bash的语法扩展会不明白。

Then no, you can't nest ${var} expressions. The bash syntax expander won't understand it.

不过,如果我理解你的问题吧,你可能看使用基本名命令 - 这条从给定的文件名的路径,如果有扩展性,条之谓也。例如,运行基本名称/some/path/to/script.sh .SH 将返回剧本

However, if I understand your problem right, you might look at using the basename command - it strips the path from a given filename, and if given the extension, will strip that also. For example, running basename /some/path/to/script.sh .sh will return script.

这篇关于可以$ {VAR}参数扩展前pressions被嵌套在bash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆