command-substitution

Shell Expansion (Command substitution) in Golang

孤街浪徒 提交于 2021-02-19 03:53:07
问题 Go has the support for variable expansion , for example: os.ExpandEnv("test- ${USER} ")` >> "test-MyName" But is there a way of expanding executables , as the way the shell behaves? Something like os.ExpandExecutable("test- $(date +%H:%M) ") >> "test-18:20" I cannot find an equivalent method for this, is there an elegant way of doing this instead of manually extracting the placeholders out, executing and then replacing them? 回答1: There's no built in function for this, but you can write a

Blank variable during bash command substitution

微笑、不失礼 提交于 2021-02-13 17:04:32
问题 I am doing command substitution and saving the result to a variable. However, the results of the command contain double quotes and this is causing the variable to be empty. When running test="$(java -version)" I get the following result: openjdk version "1.8.0_65" OpenJDK Runtime Environment (build 1.8.0_65-b17) OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode) However running echo $test yields a blank line. 回答1: The reason that test="$(java -version)" prints the result to the terminal

Blank variable during bash command substitution

元气小坏坏 提交于 2021-02-13 17:03:52
问题 I am doing command substitution and saving the result to a variable. However, the results of the command contain double quotes and this is causing the variable to be empty. When running test="$(java -version)" I get the following result: openjdk version "1.8.0_65" OpenJDK Runtime Environment (build 1.8.0_65-b17) OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode) However running echo $test yields a blank line. 回答1: The reason that test="$(java -version)" prints the result to the terminal

Blank variable during bash command substitution

梦想的初衷 提交于 2021-02-13 17:03:04
问题 I am doing command substitution and saving the result to a variable. However, the results of the command contain double quotes and this is causing the variable to be empty. When running test="$(java -version)" I get the following result: openjdk version "1.8.0_65" OpenJDK Runtime Environment (build 1.8.0_65-b17) OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode) However running echo $test yields a blank line. 回答1: The reason that test="$(java -version)" prints the result to the terminal

Use substituted string as a command in shell script

帅比萌擦擦* 提交于 2021-01-29 03:51:25
问题 Given the variables listed below: echo ${userupper}_PYTHON # YTU_PYTHON echo $YTU_PYTHON # /home/ytu/anaconda3/bin/python echo $path # foo.py Now I'd like to execute /home/ytu/anaconda3/bin/python foo.py with userupper and path . I tried $(${userupper}_PYTHON) $path but it ends up with error messages including: YTU_PYTHON: not found foo.py: not found It seems like it takes $(${userupper}_PYTHON) as bare YTU_PYTHON rather than expected $YTU_PYTHON . How should I do to make it right? Edits: The

bash logic inside command substitution

江枫思渺然 提交于 2020-12-15 00:36:21
问题 I have a little banner that I display at login fignow() { figlet -w $(tput cols) $(date +"%b %d, Week %V"); figlet -w $(tput cols) -f univers $(date +"%H:%M"); } This works fine if the additional fonts are installed to get univers , but that's not part of the default installation, so I can do the following: fignow() { figlet -w $(tput cols) $(date +"%b %d, Week %V"); if [ -f /usr/share/figlet/univers.flf ]; then figlet -w $(tput cols) -f univers $(date +"%H:%M"); else figlet -w $(tput cols) $

bash logic inside command substitution

旧巷老猫 提交于 2020-12-15 00:32:49
问题 I have a little banner that I display at login fignow() { figlet -w $(tput cols) $(date +"%b %d, Week %V"); figlet -w $(tput cols) -f univers $(date +"%H:%M"); } This works fine if the additional fonts are installed to get univers , but that's not part of the default installation, so I can do the following: fignow() { figlet -w $(tput cols) $(date +"%b %d, Week %V"); if [ -f /usr/share/figlet/univers.flf ]; then figlet -w $(tput cols) -f univers $(date +"%H:%M"); else figlet -w $(tput cols) $