Tag Info

Hot answers tagged

7

Yes, this happens because it is a "partial line". And by default zsh goes to the next line to avoid covering it with the prompt. When a partial line is preserved, by default you will see an inverse+bold character at the end of the partial line: a "%" for a normal user or a "#" for root. If set, the shell parameter PROMPT_EOL_MARK can be used to ...


6

No need for ls here. It's the shell that lists the directory content by expanding the *.sql glob. On a GNU or FreeBSD system: printf '%s\0' *.sql | sort -nz | xargs -r0 cat -- (using \0 instead of \n together with -z/-0 makes sure it also works with file names containing newline characters). Or if you have zsh: cat ./*.sql(.n) (The n glob qualifier ...


5

The result of a command substitution is broken into words using characters from IFS as separators, unless the command substitution is in double quotes. Thus " ABC" is split into a list of words, which contains one element "ABC". Use echo "$(echo " ABC")" to use the result of the command susbtitution as a string. Unlike normal Bourne/POSIX-style shells, ...


4

POSIX and Hyphens According to the POSIX standard, a function name must be a valid name and a name can consist of: 3.231 Name In the shell command language, a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit. A hyphen is not listed among the characters ...


4

See man zshzle for the pound-insert and vi-pound-insert widgets. The first will toggle a pound sign at the beginning of the buffer, the second at the beginning of the current line. Only pound-insert is bound by default, and then only in the vicmd key map, to #. To bind pound-insert, add this line to your .zshrc: bindkey '\e#' pound-insert


3

I looked through the .zshrc and /etc/zshrc of my systems. From experimenting, to expand /v/L/S/c to /var/log/squid/cache.log, I needed three settings: # These two initialize the completion system, # providing the case-sensitive expansion autoload -U compinit compinit # This sets the case insensitivity zstyle ':completion:*' matcher-list '' ...


3

incr() { var=$(< "$1") var=$((var + 1)) echo $var > "$1" } is_zero() { var=$(< "$1") [[ var -eq 0 ]] } decr is left as an exercise for the reader.


3

There is built-in command functions in zsh for this purpose functions k.pstree.n For example in case of my preexec function: $ functions preexec preexec () { local cmd=${1:-} cmd=${cmd//\\/\\\\} [[ "$TERM" =~ screen* ]] && cmd="S $cmd" inf=$(print -Pn "%n@%m: %3~") print -n "\e]2;$cmd $inf\a" cmd_start=$SECONDS }


3

In zsh, easiest is to use run-help. Bring up your previous command (Up), and press Alt+H. That will bring up the documentation for curl. Once you exit man, you'll be back to where you were. Very handy when you need to see the manual in the middle of typing a command. Note that which documentation is displayed depends on where your cursor is on the command ...


3

In both bash and zsh (and (t)csh where that feature comes from), provided that history expansion is enabled: man !!:0 (admittedly, it's not really shorter than man curl).


2

Not sure what you mean, but with zsh: accept-line() {: "${BUFFER:="my-aliased-command"}"; zle ".$WIDGET"} zle -N accept-line Pressing Enter on an empty buffer would run my-aliased-command That's redefining the accept-line widget as a function. In zle (zsh line editor) widgets, $BUFFER contains the content of the command line so far. So here we're setting ...


2

Because echo ABC and echo ABC gives the same output: ABC, and the first command echo $(echo " ABC") ==> echo ABC ==> ABC. Multiple spaces are just removed by the shell, so echo doesn't even know how many of them were present in the command-line. You can preserve spaces by quoting the whole expression in the following way: $ echo "$(echo " ...


2

With zsh, if running as root and you set EUID=1000 It will set the euid to 1000. The real uid will still be set to 0, so you can go back to EUID 0. Any program that you run would also be able to regain privileges by doing a setuid() but if the intent is to prevent unintentional damage as opposed to guard against malicious software, then that should be ...


1

Use xargs (assuming the GNU implementation) with a custom delimiter (assuming filenames don't contain newlines): ls -1d -- *.sql | sort -n | xargs -d "\n" cat --


1

One solution would be a bit of dynamic programming: Create the various unprivileged code fragments as separate files, and use a preprocessor to create the final file. This way the program can trivially be read either as separate bits or as a whole. Communication between processes would have to be done using files, which is a bit more cumbersome but makes it ...



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