7
votes
4answers
239 views

How can I suppress the space between generated arguments during brace expansion?

I used the following command to create a list of URLs that I want to test: echo -e ...
5
votes
5answers
211 views

Serialize shell variable in bash or zsh

Is there any way to serialize a shell variable? Suppose I have a variable $VAR, and I want to be able to save it to a file or whatever, and then read it back later to get the same value back? Is ...
7
votes
5answers
239 views

Making zsh default shell without root access

I am using my school's computers and would like to use zsh instead of bash. I'd like to make it default, but I cannot run a command such as $ chsh -s $(which zsh) because I don't have admin ...
3
votes
1answer
135 views

Why does this command to copy files in a for loop work in bash but not in zsh?

I'm trying to copy a bunch of files with the same name, but in different subdirectories, to a single directory, changing the names to ones based on the paths to the original files. I use a for loop ...
7
votes
2answers
217 views

alias vs export for simple commands

For simple commands like less, is it better to make an alias or to export the options? Is there any benefit of one over the other? For example, if I want less to always use the -R option to show raw ...
4
votes
3answers
805 views

Passing named arguments to shell scripts

Is there any easy way to pass (receive) named parameters to a shell script? For example, my_script -p_out '/some/path' -arg_1 '5' And inside my_script.sh receive them as: # I believe this ...
53
votes
1answer
2k views

Have backticks (i.e. `cmd`) in *sh shells been deprecated?

I've seen this comment many times on Unix & Linux as well as on other sites that use the phrasing "backticks have been deprecated", with respect to shells such as Bash & Zsh. Is this ...
1
vote
0answers
73 views

Can't open vim in zsh? [closed]

I recently decided to try out zsh, but for some reason I cannot open Vim in a zsh shell. Currently, my default shell is bash. If I open up a terminal window, then run zsh to enter a zsh shell, I have ...
-3
votes
0answers
63 views

What's the main difference between bash and zsh? [closed]

Someone told me that some commands in zsh shell may differ from the bash shell commands. So what's the main difference between zsh and bash shells?
5
votes
5answers
110 views

`ls -l` of a file and all the directories leading to it?

Before I start writing a (probably easy) script, is there a command that does the equivalent of the following one: [:~/software/scripts] % ls -ld / /usr /usr/bin /usr/bin/tee drwxr-xr-x 21 root root ...
4
votes
2answers
163 views

Completion of words on the screen as in VIM (Bash or Tmux)

How can I configure Bash, Zsh or Tmux to complete the last matching identifier on the screen? Consider this common scenario: $ git fetch remote: Counting objects: 16, done. remote: Compressing ...
1
vote
1answer
62 views

$@ and 'set env $PATH' - Why should this statement go into .inputrc?

I have a line in my .zshrc that says: set env $PATH Apparently this affects the value of $@. I have read that $@ should be empty and that I should not have any set statements in my .zshrc (at least ...
4
votes
1answer
119 views

ls -l --group-directories-first (act on symlinks as well)

ls option --group-directories-first causes directories to be listed on the top, which makes the output of ls nice and clean: ls -l --group-directories-first However, it does not act on symlinks, ...
2
votes
1answer
104 views

How can I use “emulate sh” in zsh to work with “. myscript.sh”?

I've been using emulate sh -c ". $HOME/myscript.sh" and it's working so far. However, if I'm at ~ and try to do emulate sh -c ". myscript.sh", I get .: no such file or directory: myscript.sh.. Why?
6
votes
4answers
237 views

Prevent terminal from displaying previously executed command

I have a script that allows me to log random thoughts while working on a project. In the terminal I would add a new log entry by running $ @ "some random thought" where @ is just an alias for my ...
3
votes
4answers
617 views

Searching a pattern in file names with number

I have a large number of files in a folder each with the date as the filename. For example 20130101 20130102 20130103 . . . 20130131 similarly for other months 20130201 to 20130230, the pattern is ...
4
votes
1answer
242 views

Why doesn't the process substitution <() work with ssh -F

I have some vagrant virtual machines. To log into them I issue the vagrant ssh command. I want to log into them using regular ssh command. The vagrant ssh-config outputs the suitable config file $ ...
1
vote
2answers
166 views

Get scan codes in octal format

Using showkey -s I can get the scancode of a key as a hex-number. How can I get it directly as an octal number?
4
votes
2answers
138 views

Force Bash 4 'globstar' option to ignore symlinks

Bash 4 has a fantastic option called 'globstar' that emulates (i.e. was stolen from) zsh's ** syntax for globbing across multiple directories. However, it's somewhat crippled (for my usage, at least) ...
10
votes
4answers
623 views

Search for a previous command with the same prefix when I press Up at a shell prompt

Coming from a FreeBSD world I wish to make the Linux terminal behave like FreeBSD one, especially the 9.1 version, basically when you type cd in the terminal and push the "up" arrow you can browse all ...
3
votes
1answer
174 views

Why is `xargs bash -ic echo` not the same thing as `xargs echo` or `xargs`?

I expect the command ls -d doc/* | grep -P "<some_pattern>" | xargs bash -ic echo to do the same as: ls -d doc/* | grep -P "<some_pattern>" | xargs echo that is, to give me the files ...
11
votes
1answer
716 views

How does a fork bomb work?

WARNING DO NOT ATTEMPT TO RUN THIS ON A PRODUCTION MACHINE In reading the Wikipedia page on the topic I generally follow what's going on with the following code: :(){ :|:& };: excerpt of ...
3
votes
2answers
143 views

How change prompt of subshell

I'm trying to create a simple script that, among other things, will create a subshell: #!/bin/sh # setup "${@:-$SHELL}" # teardown The question is: I need to change the default prompt, so for ...
3
votes
2answers
137 views

bash equivalent of zsh's $@[2,$#]

(NB: the motivation for this question is only to improve my bash programming know-how.) I want to know the bash equivalent of zsh expressions such as $@[2,$#], which directly address a range of a ...
5
votes
1answer
435 views

command substitution handling in fish vs. other shells (sh, bash, zsh)

The program mc (Midnight Commander) is not intended to be used for command substitution, but I would like to know why different shells behave differently when this program (and it seems like other ...
3
votes
2answers
107 views

Refer to an item in `dirs`

I use pushd to work with multiple directories in bash and zsh. I've aliased dirs to dirs -v so that I get an ordered list when I want to see what's on the directory stack: chb$ dirs 0 ...
9
votes
2answers
555 views

How do I stop bash from syntax checking sourced files?

I have the following code in a file that is sourced by both zsh and bash. if test $SHELLNAME = zsh ; then lss() { l -l ${1:-.}/*(s,S,t); } laf() { l ${1:-.}/.*(.); } lad() { l -d ...
3
votes
3answers
143 views

Persistent shell arguments

I often find myself running a series of commands on a single set of arguments. For example: $ nmap -Pn -sS 192.168.1.5 $ ssh 192.168.1.5 $ curl 192.168.1.5 $ wget -r 192.168.1.5 This can be sped ...
3
votes
2answers
166 views

Passing quotes and full strings to bash -c or zsh -c

When I am in Perl and I call system(some_command), this invokes some_command on /bin/sh. I would like it instead to run some_command in another shell such as bash or zsh. One way of running ...
6
votes
4answers
1k views

Hybrid code in shell scripts. Sharing variables

This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
5
votes
2answers
377 views

Wrap command in the prompt

Is it possible to insert a separator after the command in a prompt? This is an example: ~/Desktop: ls -al ------------------------------------- total 80 drwx------+ 6 eddie staff 204B Apr 29 ...
-1
votes
1answer
569 views

zsh: Is it worth the switch from bash? Is it the time? [closed]

I have been a bash user for years now. However, I find that zsh is increasingly gaining momentum. I came up with the following questions: Is zsh really becoming that popular? Will it compete with ...
0
votes
2answers
57 views

Command in a variable [duplicate]

I am trying to run a statement where the name of the command is in a variable. For example: my_command='/path/to/some/command' $my_command -f foo -b bar -s something else But the above does not ...
2
votes
3answers
506 views

Treatment of backslashes across shells

How do echo and printf treat backslashes in zsh, bash and other shells? Under zsh I get the following behavior: $ echo "foo\bar\baz" foaaz $ echo "foo\\bar\\baz" foaaz $ echo 'foo\bar\baz' foaaz $ ...
7
votes
4answers
2k views

Is it recommended to use zsh instead of bash scripts?

Can I assume that enough people have zsh installed to run scripts with a #!/usr/bin/env zsh as shebang? Or will this make my scripts un-runnable on too many systems? Clarification: I’m interested ...
12
votes
1answer
808 views

When is double-quoting necessary?

The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of ...
3
votes
3answers
167 views

Delete all but largest file of specific type

I am trying to organise the album art in my music collection so that only one image is assigned to each folder. My directory structure currently looks like: /path/to/music/Album Name/ ...
3
votes
1answer
225 views

How to print apparently hidden environment variables?

Environment variables can be shown with env; but, some are not shown. For example... echo $EUID might produce as result of 1000 yet env | grep EUID produces no result. What is this type of variable? ...
4
votes
4answers
2k views

Double and triple substitution in bash and zsh

Follow-up to the background part in this question. In bash I can use {!FOO} for double substitution, in zsh ${(P)FOO}. In both, the old-school (hack-y) eval \$$FOO works. So, the smartest and most ...
3
votes
3answers
184 views

${!FOO} and zsh

${!FOO} performs a double substitution in bash, meaning it takes the (string) value of FOO and uses it as a variable name. zsh doesn’t support this feature. Is there a way to make this work the same ...
5
votes
2answers
144 views

[ vs [[ : which one to use in bash scripts? [duplicate]

The zsh man page, in its section on test (aka [), explicitly advises against using it at all, and urges readers to use [[ whenever possible. The relevant section states: The command attempts to ...
1
vote
1answer
113 views

How to more easily specify tasks for batch, using command prefix tool?

The tool batch that comes with the atd daemon is pretty useful in principle, running commands only when the system utilisation falls below a certain level (by default, 1.5). However, using it (and ...
1
vote
2answers
622 views

OS X setting environment variables

I have OSX 10.8.2 with ZSH as my shell and iTerm as a terminal (don't know if the last thing is relevant). I have to mention that I'm relatively new to OSX. I'm trying to set up some environment ...
0
votes
2answers
487 views

Comparison of shells? [closed]

Do shells have any actual advantages or disadvantages? They can all run any binary, they all support pipes and > (output to file). Why would one choose bash over sh, or sh over ksh, etc? Why does ...
4
votes
3answers
133 views

Can any shell do argument-level interactive search?

Sometimes I need to reuse certain long arguments like paths. If I use history search (CTRL+R), I may find some command that contains the path, but I still need to delete anything else in the old ...
0
votes
3answers
467 views

Proper place to put shell prompt(PS1) when use sh/bash/zsh together

I'm using dash(sh) or bash or zsh. If possible, I would prefer to put in common place. I want to put proper PS1 settings when I interactive with shell, so these situation should be considered login ...
4
votes
4answers
292 views

Delete backward until met a char, like alt + bksp

Say my current line was: /tmp/path/to/file:123 Now I'm at the end of this line, now I want to delete :123 by pressing some key combination, was that possible? (colon was merely mentioned as an ...
2
votes
1answer
138 views

Zsh style arrays with Bash

Does Bash have a way to access arrays similar to Zsh, something like $ foo=(dog cat mouse) $ echo $foo[1] cat instead of $ echo ${foo[1]} perhaps using some shopt setting?
2
votes
1answer
688 views

What happened to ~ when updating oh-my-zsh?

Not sure what changed the meaning of the home path ~ in my zsh. So when I do cd ~ , I dont cd into my home but it gives me an error that /Users/carlos does not exist. How can I reset ~ to refer to ...
3
votes
5answers
2k views

Output multiple files from a single grep?

I'm not very experienced in shell scripting, but I'm trying to understand how to grep for a pattern and for each file where there is a match write a file to disk that contains the matched line from ...