variable-expansion

Use wildcard expansion to echo all variables in zsh

旧时模样 提交于 2019-12-23 17:59:41
问题 With multiple variables beginning with the same pattern can a wildcard be used to echo all matched patterns? when zzz1=test1; zzz_A=test2; zzza=test3 What is the best way to match all variables starting with zzz. Where something like echo $zzz* or for i in $zzz*; do echo $i; done would output: test1 test2 test3 回答1: So to directly answer based on comments above... No, zsh cannot expand and echo variables using a wildcard, but typeset can provide the desired result. typeset -m 'zzz*' outputs:

What is the 'reword' function in Rebol and how do I use it?

两盒软妹~` 提交于 2019-12-21 04:12:13
问题 I saw someone mention the reword function today, but documentation for it is very brief. It looks like shell script environment variable substitution, or maybe regex substitution, but different. How do I use this function and what kind of gotchas am I going to run into? 回答1: Here there be dragons! The reword function is a bit of an experiment to add shell-style string interpolation to Rebol in a way that works with the way we do things. Unlike a lot of Rebol's series functions, it really is

How to use both pipes and prevent shell expansion in perl system function?

旧城冷巷雨未停 提交于 2019-12-20 07:39:43
问题 If multiple arguments are passed to perl's system function then the shell expansion will not work: # COMMAND $ perl -e 'my $s="*"; system("echo", "$s" )' # RESULT * If the command is passed as an one argument then the expansion will work: # COMMAND $ perl -e 'my $s="echo *"; system("$s")' # RESULT Desktop Documents Downloads The system function also allows to using multiple commands and connect them using pipes. This only works when argument is passed as an one command: # COMMAND $ perl -e

Grep error due to expanding variables with spaces

妖精的绣舞 提交于 2019-12-20 01:36:08
问题 I have a file called " physics 1b.sh ". In bash, if I try x="physics 1b" grep "string" "$x".sh grep complains: grep: physics 1b: No such file or directory. However, when I do grep "string" physics\ 1b.sh It works fine. So I guess the problem is something to do with the variable not being expanded to include the backslash that grep needs to recognize the space. How do I get this to work? Using bash 3.2, mac os 10.6. Edit: Never mind, the problem was that x was set to " physics 1b" , but when I

How to Create Text Files from an Array of Values in Powershell

丶灬走出姿态 提交于 2019-12-19 10:45:09
问题 I have a text file "list.txt" with a list of hundreds of URL's that I want to parse, along with some common-to-all config data, into individual xml files (config files) using each value in "list.txt", like so: list.txt contains: line_1 line_2 line_3 The boilerplate config data looks like (using line_1 as an example): <?xml version="1.0"?> <Website xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Url>line_1.mydomain.com</Url> <Title>line_1<

get a default value when variable is unset in make

那年仲夏 提交于 2019-12-18 13:11:44
问题 (edit: question more accurate based on @Michael feedback) In bash, I often use parameter expansion: the following commands print " default value " when $VARNAME is unset, otherwise it prints the VARNAME content. echo ${VARNAME:-default value} #if VARNAME empty => print "default value" echo ${VARNAME-default value} #if VARNAME empty => print "" (VARNAME string) I did not find a similar feature on GNU make . I finally wrote in my Makefile : VARNAME ?= "default value" all: echo ${VARNAME} But I

Expand string Variable stored via Single Quote in Powershell

不想你离开。 提交于 2019-12-17 20:56:14
问题 I have a scenario where I need to construct a powershell path as $RemotePath = '$($env:USERPROFILE)\Desktop\Shell.lnk' . This variable gets passed to a remote machine where it needs to be executed. The remote machine receives this as a string variable. How do I expand the string to evaluate $env:USERPROFILE ? 回答1: Expand the string on the remote side: $ExecutionContext.InvokeCommand.ExpandString($RemotePath) 回答2: By using a double quotes. PowerShell won't expand variables inside single-quoted

Bash : Adding extra single quotes to strings with spaces

折月煮酒 提交于 2019-12-12 15:25:29
问题 When I try to passing arguments as variables to any commands in bash I can see extra quotes added by bash if the variable value has spaces. I am creating a file "some file.txt" and adding it to a variable $file. I am using $file and storing it in another variable $arg with quotes on $file. The the command I am hoping for after variable expansion by bash was find . -name "some text.txt" but I got error and actual file that got executed is, find . -name '"some' 'file.txt" Why is this happening.

How to use an array with remote variable on remote server in shell scripting?

霸气de小男生 提交于 2019-12-11 23:23:22
问题 This is what I am trying to do... #!/bin/bash array_local=(1 2 3 4 5) ssh user@server << EOF index_remote=1 echo \$index_remote echo \${array_local[\$index_remote]} EOF When I try to run the above script I get the O/P as 1 and a null value (blank space). I wanted ${array_local[$index_remote} value to be 2 instead of null, I need to access this local array using remote variable for my further work in the script.. 回答1: <<EOF results variable expansion happening on the local machine, but you

Windows batch file - Pick (up to) four random files in a folder

二次信任 提交于 2019-12-11 07:57:15
问题 As the title says, I'm trying to pick up to four random files (wallpapers) from a folder, for further processing. The folder does not contain subfolders, just *.jpg's, *.bmp's and *.png's (it may contain a Thumbs.db file, but I already took care of that). I read all the files with a for loop making something similar to an array, then I'd like to run another for loop for making the random numbers that will act as indexes for choosing the files. setlocal enabledelayedexpansion set "wps=1 2 3 4"