Hot answers tagged

289 votes

Execute a command once per line of piped input?

The accepted answer has the right idea, but the key is to pass xargs the -n1 switch, which means "Use at most 1 argument per command line": cat file... | xargs -n1 command Or, for a single ...
user avatar
34 votes
Accepted

Dealing with file names with special first characters (ex. ♫)

If the first character of file name is printable but neither alphanumeric nor whitespace you can use [[:punct:]] glob operator: $ ls *.txt f1.txt f2.txt ♫abc.txt $ ls [[:punct:]]*.txt ♫abc.txt
user avatar
  • 43.4k
28 votes
Accepted

How to change the default shell in NixOS?

In your configuration.nix, { pkgs, ... }: { ... programs.fish.enable = true; users.users.<myusername> = { ... shell = pkgs.fish; ... }; } Followed by nixos-rebuild ...
user avatar
26 votes

Fish-Shell Will Not Save my Aliases

A fish alias is actually implemented as a function. To save a function, you need funcsave. So this is the sequence alias foo=bar funcsave foo That creates ~/.config/fish/functions/foo.fish which will ...
user avatar
23 votes
Accepted

Run a command only if the previous command was successful in Fish (like && in bash)

Instead of &&, which doesn't exist in fish, use ; and the command and: cd /study; and ls -la According to the fish tutorial: Unlike other shells, fish does not have special syntax like &...
user avatar
  • 1,341
21 votes
Accepted

Share environment variables between bash and fish

bash has special syntax for setting environment variables, while fish uses a builtin. I would suggest writing your .env file like so: setenv VAR1 val1 setenv VAR2 val2 and then defining setenv ...
user avatar
20 votes

What's the easiest way to detect what signals are being sent to a process?

Since Stéphane posted this information as a comment, but I found this information to be more useful than any existing answers, I'm reposting the comment as an answer. For Linux only: strace prints ...
user avatar
  • 7,823
18 votes
Accepted

find -exec not working in fish

fish happens to be one of the few shells where that {} needs to be quoted. So, with that shell, you need: find . -type f -name '*.c' -exec chmod 644 '{}' + When not quoted, {} expands to an empty ...
user avatar
15 votes

Does Bash have similar features such as Fish's autosuggestions and highlighting?

As mentioned in here, it can be achieved through ble.sh # Quick TRIAL without installation # requires the commands git, make (GNU make), and gawk git clone --recursive https://github.com/akinomyoga/...
user avatar
15 votes
Accepted

How can I check if a shell is login/interactive/batch in fish?

Use the status command: $ fish -c 'status --is-interactive; and echo yes; or echo no' no $ status --is-interactive; and echo yes; or echo no yes Also, status --is-login. That should cover your bases....
user avatar
14 votes

Execute a command once per line of piped input?

If you need to control where exactly the input argument is inserted into your command line or if you need to repeat it several times then you can use xargs -I{}. EXAMPLE #1 Create an empty folder ...
user avatar
  • 1,455
12 votes
Accepted

In the Fish shell, how can I join an array with a custom separator?

Since fish 2.3.0 you can use the string builtin: string join ',' $ASD The rest of this answer applies to older versions of fish. One option is to use variable catenation: echo -s ,$ASD This adds an ...
user avatar
12 votes
Accepted

fish: sudo: !!: command not found

I haven't found a inbuilt replacement for !! in Fish however you can write a function that allows you to keep using !! Taken from this answer https://superuser.com/a/719538/226822 function sudo --...
user avatar
  • 410
12 votes
Accepted

fish shell : exec format error

You need a shebang line if the executable file cannot be run natively by the kernel. The kernel can only run machine code in a specific format (ELF on most Unix variants), or sometimes other formats (...
user avatar
11 votes
Accepted

Fish-Shell Will Not Save my Aliases

It basically boiled down to: Open ~/.config/fish/config.fish in your favorite editor. If it's not already there, it'll make it for you. (Don't su it though.) Add all the aliases you want. It'll ...
user avatar
  • 609
11 votes
Accepted

Run fish script in background?

fish does not fork to execute subshells, so it is not yet possible to run fish script in the background - see https://github.com/fish-shell/fish-shell/issues/563 A hackish workaround is to invoke ...
user avatar
11 votes
Accepted

Fish shell testing for existence of file in $PATH

Use type in fish like in Bourne-like shell: if type -q figlet hostname | figlet end Or to limit to executables in $PATH (ignoring functions, builtins): if command -s figlet > /dev/null ...
user avatar
11 votes
Accepted

Why can't I list a directory with read permissions?

Some preparations, just to make sure that ls does not try more things than it should: $ unalias ls 2>/dev/null $ unset -f ls $ unset CLICOLOR Demonstration of the r directory permission: $ ls -...
user avatar
  • 226
11 votes

Why I can't add fish to /etc/shells?

You're doing it wrong. You should be using the chsh command to change your user's shell. $ chsh -s /usr/local/bin/fish OSX On OSX you apparently have to add this to the /etc/shells file as ...
user avatar
  • 346k
10 votes

Share environment variables between bash and fish

There is (now?) an easier way, per @Zanchey's answer here Fish Shell: How to set multiple environment variables from a file using export The digest though is: Fish: echo -e "foo=3\nfoobar=4" > ....
user avatar
10 votes

fish: sudo: !!: command not found

The !! syntax is part of the bash history substitution feature, which fish does not implement. See this link for a discussion. Please feel free to weigh in there on what you think fish ought to do. ...
user avatar
10 votes
Accepted

Does one string contain another in fish shell?

It looks to me like there's a string function for that purpose: $ set STRING something here $ string match -q "other_string" $STRING; and echo yes $ set STRING some other_string here $ string match -...
user avatar
  • 63.4k
10 votes
Accepted

xargs | Use input as command

In xargs -I replstr utility arguments, POSIX requires that the replstr be only substituted in the arguments, not utility. GNU xargs is compliant in that regard (busybox xargs is not). To work around ...
user avatar
9 votes

How to edit the fish shell startup script?

bash and fish have incompatible syntax, so they cannot share startup files. You can put startup commands in ~/.config/fish/config.fish. However this is usually unnecessary! For creating functions or ...
user avatar
9 votes
Accepted

Issue with type force PATH search

This: force a PATH search for each NAME, even if it is an alias, does not mean that bash will expand the alias and then search for the expanded command. It means that, if there were a command foo, ...
user avatar
  • 64.3k
8 votes

How to make zsh completion show the first guess on the same line (like fish's)?

Follow the steps here to get other features as well: https://github.com/abhigenie92/zsh_to_fish Install oh-my-zsh sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/...
user avatar
8 votes

How to stop fish shell from underlining path?

fish underlining valid path by defaul: $ set | grep fish_color_valid_path fish_color_valid_path --underline You only need to reset it: $ set fish_color_valid_path $ ls /etc/fstab
user avatar
  • 144k
8 votes

How to access bash aliases in fish

I stumbled upon this post,the first script is quite nice but I really like using one file for all my aliases. Another simpler and neat way to do it would be: Move all your aliases to ~/.bash_aliases ...
user avatar
7 votes

how do I reference a variable in fish shell with a default fallback

To reference a variable and provide a default value in-line you can use command substitution containing a conditional which does echo on both branches. > echo (if set -q someVar; echo $someVar; ...
user avatar

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