Hot answers tagged

7

/bin/sh is a symlink, and overwriting didn't actually delete anything, it just invalidates the link. Which is a problem because all kinds of scripts use /bin/sh in the shebang header. This is probably why various random things are also failing. You need to, as root or via sudo:1 cd /bin rm sh ln -s dash sh Hopefully the meaning of that is clear enough, ...


4

GNU grep supports three types of regular expressions: Basic, Extended (ERE) and Perl (PCRE). In GNU grep, EREs don't provide functionality over basic ones, but some characters have special meanings, such as the plus sign. Source: man page. \d does not mean anything special in an ERE; it's just the character d. To express digits, use [[:digit:]] or the old [0-...


3

There are several issues with your code: for i in (ls *.log); do Instead of (...), it should be $(...), however, it is not needed at all, because ... you should not parse the output of ls, rather use for f in *.log; do Your $i is not a counter, but the file names, you have to add a counter manually. i=0 before the loop and increment, e.g. with i=$((i+1)) ...


3

Note: I would not do the following. It is not safe, and also there are enough other possibilites to destroy your system. Why exactly picking this one? With great sudo rights, comes great responsibility. However, to keep even root from editing sudoers file, you can make it immutable by running: sudo chattr +i /etc/sudoers Then add the followign aliases to ...


2

Though sub-optimal, the following method works fine in a pinch: declare -A fundocs_; doc() { fundocs_[$1]=$2; } help_doc() { echo "$1: ${fundocs_[$1]}"; } doc hi_from_fun "Send a short greeting" hi_from_fun() { echo "Hi there"; } help_doc hi_from_fun will print documentation as follows: hi_from_fun: Send a short greeting ...


2

words=(hello world foo bar) grep -F -f <(printf "%s\n" "${words[@]}") text.txt This uses process substitution to provide a "file" containing each word on its own line. The -f option tells grep to read its list of patterns to match from a file. The -F option tells grep that the patterns are fixed strings, not regular ...


1

Device nodes for drives aren't guaranteed to be consistent across reboots. They're allocated on a first-seen basis, at boot time. This may vary due to hardware changes, kernel changes, module loading order, minor variations in timing, etc. If you want persist device node naming, use the symlinks under /dev/disk/*/. They will always point to the correct ...


1

$ awk '{ sum[$1] += ($2 >= 30) } END { for (i in sum) if (!sum[i]) print i }' file 1599026 This uses awk to create a sum for each unique number in the first column of your data in the file called file. The sum for a number is the number of times the second column's value is greater than or equal to 30. At the end of the awk code, in the END block, all ...


1

This type of splitting has nothing to do with IFS. It is the very basic kind of splitting that converts a line into words. Words are the individual tokens over which a shell could act. Like reading a sentence is done by dividing it into words first and then understanding what the words mean. The only way to avoid such splitting is by quoting. That is the ...


1

A program (script, application, whatever) does not get to see the command line that invoked it. It gets given a series of zero of more parameters parsed by the invoking shell. For example, when you run ls f* it's not ls that handles the f*, it's the shell. If you had three files beginning with f, then ls f* might be parsed by the shell to become ls final ...


1

See info zsh 'Parameter Expansion': ${NAME-WORD} ${NAME:-WORD} If NAME is set, or in the second form is non-null, then substitute its value; otherwise substitute WORD. In the second form NAME may be omitted, in which case WORD is always substituted. That's a feature inherited from the Bourne shell (from the late 70s) and present in all Bourne-like or ...


1

$ perl -lne ' s/_tr.*/_/; unless (defined($prefixes) && m/^($prefixes)_/) { $prefixes{$_}++; $prefixes=join("|", map +( "\Q$_\E" ), keys %prefixes); }; END { print join("\n", sort keys %prefixes) }' <(sort input.txt) pj1_ex_24_i535_ pj3_ex_16_i535_ pj6_ex_14_i535_ pj6_ex_18_i535_ or even ...


1

In the bash shell, for the list of aliases, reserved words, functions and external commands in directories of $PATH (assuming none of them contain newline characters) sorted alphabetically: compgen -ac | sort


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