gnu-coreutils

How do I read the source code of shell commands?

故事扮演 提交于 2019-11-27 16:34:28
I would like to read the actual source code which the linux commands are written with. I've gained some experience using them and now I think it's time to interact with my machine at a deeper level. I've found some commands here http://directory.fsf.org/wiki/GNU . Unfortunately I wasn't able to find basic commands such as 'ls' which seems to me easy enough to begin. How exactly do I read the source code of the simple shell commands like 'ls'? I'm running on Ubuntu 12.04 All these basic commands are part of the coreutils package. You can find all information you need here: http://www.gnu.org

How to extract the first two characters of a string in shell scripting?

流过昼夜 提交于 2019-11-27 09:39:12
问题 For example, given: USCAGoleta9311734.5021-120.1287855805 I want to extract just: US 回答1: Probably the most efficient method, if you're using the bash shell (and you appear to be, based on your comments), is to use the sub-string variant of parameter expansion: pax> long="USCAGol.blah.blah.blah" pax> short="${long:0:2}" ; echo "${short}" US This will set short to be the first two characters of long . If long is shorter than two characters, short will be identical to it. This in-shell method

Less gets keyboard input from stderr?

梦想的初衷 提交于 2019-11-27 07:37:11
问题 I'm taking a look at the code to the 'less' utility, specifically how it gets keyboard input. Interestingly, on line 80 of ttyin.c, it sets the file descriptor to read from: /* * Try /dev/tty. * If that doesn't work, use file descriptor 2, * which in Unix is usually attached to the screen, * but also usually lets you read from the keyboard. */ #if OS2 /* The __open() system call translates "/dev/tty" to "con". */ tty = __open("/dev/tty", OPEN_READ); #else tty = open("/dev/tty", OPEN_READ);

Display two files side by side

此生再无相见时 提交于 2019-11-26 23:55:36
问题 How can 2 unsorted text files of different lengths be display side by side (in columns) in a shell Given one.txt and two.txt : $ cat one.txt apple pear longer line than the last two last line $ cat two.txt The quick brown fox.. foo bar linux skipped a line Display: apple The quick brown fox.. pear foo longer line than the last two bar last line linux skipped a line paste one.txt two.txt almost does the trick but doesn't align the columns nicely as it just prints one tab between column 1 and 2

Howto split a string on a multi-character delimiter in bash?

萝らか妹 提交于 2019-11-26 21:55:29
问题 Why doesn't work the following bash code? for i in $( echo "emmbbmmaaddsb" | split -t "mm" ) do echo "$i" done expected output: e bb aaddsb 回答1: Since you're expecting newlines, you can simply replace all instances of mm in your string with a newline. In pure native bash: in='emmbbmmaaddsb' sep='mm' printf '%s\n' "${in//$sep/$'\n'}" If you wanted to do such a replacement on a longer input stream, you might be better off using awk , as bash's built-in string manipulation doesn't scale well to

How do I read the source code of shell commands?

ε祈祈猫儿з 提交于 2019-11-26 18:42:01
问题 I would like to read the actual source code which the linux commands are written with. I've gained some experience using them and now I think it's time to interact with my machine at a deeper level. I've found some commands here http://directory.fsf.org/wiki/GNU. Unfortunately I wasn't able to find basic commands such as 'ls' which seems to me easy enough to begin. How exactly do I read the source code of the simple shell commands like 'ls'? I'm running on Ubuntu 12.04 回答1: All these basic