Tag Info

Hot answers tagged

13

Use printf builtin: $ printf %s\\n localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,.preload} localhost:8080/reports/promos/130 localhost:8080/reports/promos/130.pdf localhost:8080/reports/promos/130.xls localhost:8080/reports/promos/130.xlsx localhost:8080/reports/promos/130.csv ...


5

setopt extendedglob cat <->.csv > all.csv Where <-> matches any positive integer decimal number, will concatenate all those (in lexical order, which for 0 padded numbers is the same as numerical order) into all.csv. That will double the space on disk though. If you don't intend to keep the original files, you could do: for i in ...


5

This is tagged zsh, so I suggest the zsh builtin print : print -l localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,.preload} -l prints arguments on separate lines.


5

You could store the brace expansion in an array, then output it in the manner of your choosing: urls=( localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,.preload} ) Then printf "%s\n" "${urls[@]}" or (IFS=$'\n'; echo "${urls[*]}") The echo example looks weird because: it's run in a ...


3

You must use "${(@k)array}", "${(k)array}" only expands to the non-empty keys: typeset -A array array=(k1 v1 k2 v2 k3 v3) for k in "${(@k)array}"; do printf "%s -> %s\n" "$k" "$array[$k]" done Then: $ zsh test.zsh k1 -> v1 k2 -> v2 k3 -> v3 You can also replace for loop with key, value expansion: printf '%s -> %s\n' "${(@kv)array}" ...


3

zsh has different parameter substitution than Bash, which is documented in man zshexpn. It supports a variety of modifiers to expansion behaviour, which are put in parentheses before the variable name: ${(X)name}. The modifier to include array keys (including for associative arrays) is k: ${(k)array} expands to the list of keys in the array, except that if a ...


2

If you use redirection, that will either append or overwrite contents to one file. If you want to append to one file, use: cat file.csv file2.csv file3.csv >> all.csv This next command will overwrite to all.csv: cat file.csv file2.csv file3.csv > all.csv But say you want to move all CSV files to one csv in a given directory (to append to): cat ...


2

The problem is the brace expansion is adding the space, and echo is adding the newline. So using single responsibility principle, handle the newline separately. echo -e localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,.preload} | tr " " "\n"


2

Set the SH_GLOB option. setopt sh_glob From man zshoptions: SH_GLOB Disables the special meaning of (',|', `)' and '<' for globbing the result of parameter and command substitutions, and in some other places where the shell accepts patterns. If SH_GLOB is set but KSH_GLOB is not, the ...


2

In zsh, history is an alias for fc -l 1, so when you do history -20 it get replaced by fc -l 1 -20 which just won't work, so instead use fc directly: ➜ ~ fc -l -20 10095 grep -R PAPER /usr/lib/locale/ 10096 man locale 10097 man 7 locale 10098 mc 10099 history 10100 history --help 10101 run-help history 10102 history 20 10103 history 1 20 10104 ...


2

Corrections apply automatically because they are first on a group list, before original. You can change that with zstyle ':completion:*' group-order original corrections And the result is Credit for the final solution goes to Stéphane Chazelas.


1

If you have many nested fancy aliases and you are not sure what zsh is actually doing with them and in which order options are passed to command then you can always start zsh with -x option. This will print commands and arguments as they are executed. Be aware however that this option is intended rather for debugging purpose so it prints a lot of useless ...


1

Note that Ctrl-Alt-E in bash does not only expand aliases. It also expands variables, command substitution (!), process substitution (!), arithmetic expand and removes quotes (it doesn't do filename generation (globbing) or tilde expansion). It doesn't always manage to expand aliases. So while it has its uses, it's important to realise its outcome ...


1

If you stuff a command line into a function definition and then print out the function, the aliases will be expanded. You'll also get normalized whitespace. % alias foo='bar -1' % alias bar='qux -2' % f () foo -3 % which f f () { qux -2 -1 -3 } To put all this into an interactive command, you can make a zle widget. You can define a function ...


1

AFAIK, ${!...} doesn't exist. I suppose you want: ${(k)array[@]}, or simply ${(k)array}. For more information, see the zshexpn(1) man page, which says for the k expansion flag: "If name refers to an associative array, substitute the keys (element names) rather than the values of the elements."


1

The first thing to know, in zsh, history meaning fc -l. Then read man zshbuiltins, section about fc command: Select a range of commands from first to last from the history list. The arguments first and last may be specified as a number or as a string. A negative number is used as an offset to the current history event number. A string specifies ...


1

You can disable the PATTERN(QUALIFIERS) syntax by unsetting the bare_glob_qual option: setopt no_bare_glob_qual If the option extended_glob is set (and you should set it, the only reason not to set it is for backward compatibility with rare scripts that use unusual syntax), then there is another syntax for glob qualifiers: PATTERN(#qQUALIFIERS). So you ...


1

Any sub directory to a directory containing a git repo will be identified as a git repo. I had accidentally created a git repo in / which resulted in all directories being identified as git repos.


1

You could do something like: alias forever='while ((1))' \ try-again='continue 2' \ ok-done='break' forever { for i ("$list[@]") { (( i == 2 )) && try-again } ok-done } Note that you need "$list[@]" instead of $list if you don't want to omit the empty elements. Not a lot more legible than: for ((i = 1; i <= $#list; ...



Only top voted, non community-wiki answers of a minimum length are eligible