Tag Info

Hot answers tagged

7

The purpose of ${1+"$@"} for portability. POSIX defined $@ would expand to nothing if there're no positional arguments. But original Bourne shell (or /bin/sh in Solaris 10 and before) would expand it to "". Using ${1+"$@"} is a work around for this, since when "$@" only expanded if $1 was set. Unfortunately, this construct doesn't work in zsh 3.x and pre ...


4

Using line continuations like that adds spaces into your string: the sequence backslash-newline-whitespace will be replaced by a single space. Just using a variables will go a long way towards improved readability: url="reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongstring" { somecheck || somecomand ...


3

According to the zsh user guide, aliases should be defined in ~/.zshrc: You may be able to think of some aliases you want to define in your startup files; .zshrc is probably the right place. It also has a tip for keeping your ~/.zshrc clean: I only tend to use aliases in interactive shells, so I define them from .zshrc, but you may want to use ...


3

do is a reserved word in the shell. It's part of the syntax of while and for loops. When you define it as an alias, the alias takes precedence over the reserved word. So the shell sees, after alias expansion: if [ -d "$_dir/pre" ]; then for config in "$_dir"/pre/**/*(N-.); ssh -L xxxx:127.0.0.1:xxxx -N -f -l user -p xxxx xx.xx.xxx.xxx . $config done ...


3

In most cases, that would be the redirection operator (<): $ tr 'a' 'b' /path/to/file ## fails because `tr` works on streams tr: extra operand ‘file’ Try 'tr --help' for more information. $ tr 'a' 'b' < /path/to/file ## works because the file's contents are passed to tr Both command substitution and the redirection operator are defined by POSIX ...


3

From the bash documentation: Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: \a alert (bell) (...) \nnn the eight-bit character whose value is the octal ...


2

For zsh there are three widgets, which can bound to that effect: push-input, push-line and push-line-or-edit (see man 1 zshzle for more information). On the top-level prompt (PS1) they behave the same: The current buffer is pushed onto the buffer stack and then cleared. On the next promp (or when calling the widget get-line) the buffer will be popped of the ...


1

Place your environment variables in your ~/.zshrc file, they will get sourced automatically on each zsh session.


1

Well, you could simplify it slightly to: $ [ -f /dev/null ] || sed 's/a/A/g' <(echo "thisis""avery"\ "long""string"\ "Ihave""separated"\ "into""smaller"\ "substrings") thisisAverylongstringIhAvesepArAtedintosmAllersubstrings The important point is to not have any extra whitespace in the input string, so no spaces around the \. Glenn's suggestion to ...


1

!! is history expansion. The first ! starts a history expansion; !! has the event designator meaning the previous command. You can access the command history via the fc and history builtins and via the history variable. Since --vimgrep only makes sense with ag, your alias would be more useful if it applied to the last ag command. You can locate the ...


1

Why not just use a second shell to check for details? I use screen for that, or just switch to a second desktop where I (usually) also have an open shell. This way, I only spend one extra shortcut to switch to the backup shell and one more to switch back. Of course, this technique won't work in the last case you describe, because my second shell won't have ...



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