Tag Info

Hot answers tagged

24

You didn't specify which shell you are using, so let this be excuse to advertise zsh. Yes, we do have more history for cd, namely cd -2, cd -4 etc. Very convenient is cd -TAB, especially with completion system and colors enabled: This is what I have in .zshrc: setopt AUTO_PUSHD setopt PUSHD_MINUS setopt CDABLE_VARS zstyle ':completion:*:directory-stack' ...


23

With (t)csh, bash or zsh history expansion you could write: vagrant up && !#:0 ssh But, seriously, you wouldn't


23

The command you are looking for is pushd and popd. You could view a practical working example of pushd and popd from here. mkdir /tmp/dir1 mkdir /tmp/dir2 mkdir /tmp/dir3 mkdir /tmp/dir4 cd /tmp/dir1 pushd . cd /tmp/dir2 pushd . cd /tmp/dir3 pushd . cd /tmp/dir4 pushd . dirs /tmp/dir4 /tmp/dir4 /tmp/dir3 /tmp/dir2 /tmp/dir1


23

Your confusion stems from the fact that many popular languages (especially C-based ones) stop evaluating && sequences when 0 is encountered, because 0 is considered false and everything else is true. In Bash, however, that's not the case. By convention, in POSIX systems (and all other Unix-like systems), return code 0 is considered SUCCESS (there was ...


19

zsh like most modern shells have a choice between two different keyboard mappings for command-line editing: a vi one and an emacs one. In some shells (like tcsh or readline-based ones like bash), the emacs one is the default and probably the one you expect. With zsh, you get emacs mode by default unless $EDITOR or $VISUAL contains vi (if you're a ...


14

Oooh, I found an explanation. To quote the relevant part: The zsh shell comes with (more than one) great feature(s), such as remote tabcompletion. If you for example want to copy a file over scp, simply hit tab at any part of the filename on the remote host. zsh is able to establish an ssh session on the background, and fetch the related information ...


13

You could do: eval vagrant\ {'up &&',ssh} but that would not make it easier. You could always make a function doall() { cmd=$1; shift for arg do "$cmd" "$arg" || return done } And then: doall vagrant up ssh


11

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 ...


10

To answer your question regarding "more history". No the cd - feature in Bash only supports a single directory that you can "flip" back to. As @Ramesh states in his answer. If you want a longer history of directories you can use pushd and popd to save a directory or return to a previous one. You can also see the list of what's currently in the stack with ...


8

The best way, to look at zsh documentation is using info. If you run info zsh, you can use the index (think of a book's index) to locate the section that describes the zmodload command. Press i, then you can enter zmo and press Tab. You'll get straight to the zmodload builtin description which will tell you all about it. In short, zmodload -F loads the ...


8

Different, documented behavior in zshmisc A list is a sequence of zero or more sublists, in which each sublist is terminated by ;, &, &|, &!, or a newline. This terminator may optionally be omitted from the last sublist in the list when the list appears as a complex command inside (...) or {...}. When a sublist is terminated ...


8

Because there's no command called emacs -nw. There's a command called emacs to which you can pass a -nw option. To store commands, you generally use functions: foo() emacs -nw "$@" foo ... To store several arguments, you generally use arrays: foo=(emacs -nw) $foo ... To store a string containing several words separated by spaces and have it split on ...


8

The return value from commands are different from typical boolan values. 0 is success when executing a command, anything else is failure. && expects 0 to me success here for that reason.


7

List all shell variables bash : use set -o posix ; set. The POSIX options is there to avoid outputing too much information, like function definitions. zsh : use typeset Shell variables and environment variables An environment variable is available to exec()-ed child processes (as a copy. if parent process change the variable, the childs are not aware of ...


7

With zsh, use glob qualifiers: mv home*(.) dst moves only regular files. While mv home*(^/) dst moves files of any type except directories. mv home*(^-/) dst would also exclude symlinks to directories.


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 ...


6

You can install and use my dirhistory utility for bash. Basically, it's a daemon that collects directory changes from all your shells, and a Cdk program that displays the history and lets you pick any directory to switch to (so you're not limited to a stack).


6

I'll stick to scripting features. Rich interactive features (command line edition, completion, prompts, etc.) tend to be very different, achieving similar effects in wholly incompatible ways. What features are in zsh and missing from bash, or vice versa? gives a few pointers on interactive use. The closest thing to bash would be ATT ksh93 or mksh (the Korn ...


6

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 ...


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 ...


6

Both are wrong with the zsh default option settings. You can easily see what's going on by using echo as the command instead of mv. Interactively, it looks like you have the null_glob option set. According to the zsh documentation that option is not set by default. What happens with that option unset depends on whether another option, nomatch, is set or ...


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

Well, you could always just do ~ for i (drop create migrate) echo bundle exec rake db:$i bundle exec rake db:drop bundle exec rake db:create bundle exec rake db:migrate Or ~ echo bundle exec rake db:{drop,create,migrate} bundle exec rake db:drop db:create db:migrate


5

In a shell command like PATH=~/bin:/opt/texbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games the tilde is expanded to your home directory when the shell command is executed. Thus the resulting value of PATH is something like /home/theconjuring/bin:/opt/texbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games. Make sure that the tilde ...


5

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 }


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, ...


5

This feature can be tuned with ZLE_REMOVE_SUFFIX_CHARS and ZLE_SPACE_SUFFIX_CHARS shell parameters. If the ZLE_REMOVE_SUFFIX_CHARS variable is set, it should contain a set of characters that, when typed, will cause automatic suffixes from the completion to be removed. If ZLE_REMOVE_SUFFIX_CHARS is unset, the default behaviour equates to ...


5

The fc built-in command allows you to extract commands from the history using a number of criteria (see man zshbuiltins for details). fc stands for “fix command”, and when invoked with no parameters it opens an editor with the last command entered. You can use all your editor’s features to change the command, and when you save and exit zsh runs the fixed ...


5

oh-my-zsh enable two things, which cause this behavior: AUTO_CD: If command can not execute, and command is a directory name, perform cd to that directory CDABLE_VARS: If the argument to a cd command (or an implied cd with the AUTO_CD option set) is not a directory, and does not begin with a slash, try to expand the expression as if it were preceded by a ~ ...


5

This should do the trick: awk -F '[<>]' ' NR!=1 && FNR==1{printf "\n"} FNR==1{sub(".*/", "", FILENAME); sub(".xml$", "", FILENAME); printf FILENAME} /double/{printf " %s", $3} END{printf "\n"} ' $path_to_xml/*.xml > final_table.csv Explanation: awk: use the program awk, I tested it with GNU awk 4.0.1 -F ...



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