Hot answers tagged

127

If your input only contains ASCII characters, you could use tr like: tr A-Z a-z < input or (less easy to remember and type IMO; but not limited to ASCII latin letters, though in some implementations including GNU tr, still limited to single-byte characters, so in UTF-8 locales, still limited to ASCII letters): tr '[:upper:]' '[:lower:]' < input if ...


76

If the file(s) in question contain really lots of data sending the signal can actually get to cat before it finishes. What you really observe is the finite speed of your terminal - cat sends the data to the terminal and it takes some time for the terminal to display all of it. Remember, that usually it has to somehow redraw the whole output window for each ...


48

$SHELL is not necessarily your current shell, it is the default login shell. To check the shell you are using, try ps $$ This should work on most recent Unix/Linux with a ps that supports the BSD syntax. Otherwise, this is the portable (POSIX) way ps -p $$ That should return something like this if you are running tcsh: 8773 pts/10 00:00:00 tcsh If ...


34

Add to the following to ~/.inputrc: # Press up-arrow for previous matching command "\e[A":history-search-backward # Press down-arrow for next matching command "\e[B":history-search-forward Explanation ~/.inputrc is the configuration file for GNU readline. Many shells, including bash and tcsh use readline for command line editing. The two lines above will ...


33

In the case of csh and tcsh, it records the value of the $HOME variable at the time the shell was started (in its $home variable as noted by @JdeBP). If you unset it before starting csh, you'll see something like: $ (unset HOME; csh -c cd) cd: No home directory. For bash (and most other Bourne-like shells), I see a different behaviour than yours. bash-4....


30

Using vim, it's super simple: $ vim filename gg0guGZZ Opens the file, gg goes to the first line, 0, first column. With guG, lowers the case of all the characters until the bottom of the file. ZZ saves and exits. It should handle just about anything you throw at it; it'll ignore numbers, it'll handle non ASCII. If you wanted to do the opposite, turn the ...


21

< /dev/null is used to instantly send EOF to the program, so that it doesn't wait for input (/dev/null, the null device, is a special file that discards all data written to it, but reports that the write operation succeeded, and provides no data to any process that reads from it, yielding EOF immediately). & is a special type of command separator used ...


18

Follow the actual installation instructions properly! You buried this in a comment:The environment variables are written to settings[32|64].(c)sh at "/opt/Xilinx/14.7/ISE_DS". To launch the Xilinx tools, first source the settings script:C-shell 64 bit environment...source /opt/Xilinx/14.7/ISE_DS/settings64.csh This is just part of a larger set of ...


17

I like dd for this, myself. <<\IN LC_ALL=C 2<>/dev/null \ dd conv=lcase hi Jigar GANDHI jiga IN ...gets... hi jigar ghandi jiga The LC_ALL=C is to protect any multibytes in input - though any multibyte capitals will not be converted. The same is true for (GNU) tr - both apps are prone to input mangling in any non-C locale. iconv can be ...


14

The script is declared as #!/bin/csh -f The syntax also matches that of csh. You are running it as sh build.sh Since csh is compatible with neither Bourne nor POSIX sh, the mismatch causes lots of syntax errors. The correct way to run build.sh is either csh build.sh or by making it executable (chmod +x build.sh) and running it directly, letting the ...


13

You can also use Perl 5: perl -pe '$_=lc' temp The option -p tells perl to run the specified expression once for each line of input, printing the result, i.e. the final value of $_. -e indicates that the program will be the next argument, as opposed to a file containing the script. lc converts to lowercase. Without an argument, it will operate on $_. And $...


12

For bash, this will reload now the currently defined mappings bind -f ~/.inputrc


12

This inconsistency is in fact the first reason in the list of reasons why csh programming is considered harmful. Or what if you just want to throw away stderr and leave stdout alone? Pretty simple operation, eh? cmd 2>/dev/null Works in the Bourne shell. In the csh, you can only make a pitiful attempt like this: (cmd > /dev/tty) &...


11

Try this one: sed '1{/^$/d}' file


11

bash doesn't have a foreach; this script is probably meant to run in csh or tsch. If you are invoking the script with ./myscript.csh, make sure its first line is #!/bin/csh (or whatever the full path to that shell is on your system).


10

From the tcsh man page. excerpt history The first word indicates the number of history events to save. The optional second word (+) indicates the format in which history is printed; if not given, %h\t%T\t%R\n is used. The format sequences are described below under prompt; note the variable meaning of %R. Set to 100 by default. Example $...


10

You're overcomplicating this. I don't understand what you're trying to do with all.txt. To enumerate the files in a directory, don't call ls: that's more complex and doesn't work reliably anyway. Use a wildcard pattern. To strip the extension (.txt) at the end of the file name, use the suffix stripping feature of variable substitution. Always put double ...


9

You need to capture the matched pattern and then use it in the replacement with a modifier: sed 's/\([A-Z]\)/\L\1/g' temp The \(...\) "captures" the enclosing matched text, the first capture goes to \1, the next to \2, etc. The numbering is according to opening brackets in case of nested captures. The \L converts the captured pattern to lower case, there'...


8

From the command line, you can also use the $0 variable to determine which shell you are using. e.g.: ~$ echo $0 /bin/bash ~$ ksh $ echo $0 ksh Note: you cannot determine the shell using $0 within a script, because $0 will be the script itself.


8

In ksh93: PS1='${PWD#${PWD%?/*/*/*}?/} \$ ' share/doc/libnl-3-dev $ _ PS1='[${HOSTNAME%%.*}:${PWD#${PWD%?/*/*/*}?/}] $USER% ' [host:share/doc/libnl-3-dev] user% _ If you want it to also replace $HOME with ~, something nastier is needed: PS1='$(d=${PWD/#$HOME/"~"};printf %s "${d#${d%?/*/*/*}?/}") $ ' ~/w/maemo $ cd sb2-pathmaps w/maemo/sb2-pathmaps $ _ ...


7

If you mean keyboard shortcut at the prompt of interactive bash shells, you could bind the shell-backward-word and shell-forward-word to some sequence of characters sent upon some key or combination of key presses. Like if pressing Ctrl-Left sends the sequence \e[1;5D on your terminal like it does in xterm, you could do: bind '"\e[1;5D": shell-backward-...


7

These variables set the history to merge itself instead of overwrite, and not save duplicates: set history=1000 set histdup=erase set savehist=(1000 merge) the secret sauce is this line: alias precmd 'history -S; history -M' which will save and merge your history prior to printing the prompt - i.e. after each command you type. all of the above should be ...


7

if ("$myVar" == "") then echo "the string is blank" endif Note that in csh, it is an error to attempt to access an undefined variable. (From a Bourne shell perspective, it's as if set -u was always in effect.) To test whether a variable is defined, use $?myVar: if (! $?myVar) then echo "myVar is undefined" else if ("$myVar" == "") then echo "...


6

Not all bash line editing is controlled from ~/.inputrc; much of it is configured via the bind builtin. In this case, you want something like bind -x '"\C-gu":uptime' in your ~/.bashrc.


6

</dev/null disconnects the program's input from the terminal. Some programs react differently depending on what their standard input is connected to. With the redirection </dev/null, the program can tell that its input is not coming from a terminal, and will receive an end-of-file indication immediately if it tries to read from its standard input. The ...


6

With tcsh 6.17.01 and above: set globdot du -s -- * With older ones: du -s -- * .[^.]* ..?* (interestingly, that works better than its POSIX counterpart (* .[!.]* ..?*) because in tcsh (and in zsh in csh emulation (cshnullglob option)), contrary to POSIX shells, those pattern that don't match any file get expanded to nothing instead of themselves) With ...


6

Doesn't work for me with the backslashes but I can explain this one to you: echo "$PATH" | awk 'NF && !x[$0]++' RS='[:|\n]' The record separator (RS) is set to one of the characters ":", "|" and newline. $PATH is usually just one line with elements separated by ":". This makes awk behave like the paths were not separated by ":" but each on its own ...


6

What's happening is that FreeBSD and Linux use different shells by default. FreeBSD defaults to tcsh, which had better interactive features than bash in the past (but bash has caught up) but markedly worse scripting features. The most straightforward way to get the environment you're used to would be to switch your shell to tcsh on Linux. Provided that tcsh ...


6

The .inputrc file is not a file to be sourced. It should be taken into account automatically by bash or other software using the readline library. If this doesn't work, add a space after the colon, e.g. "\e[1;5C": forward-word (I've always seen a space in this config file).


6

The only shells I know which has a builtin command called where is the tcsh and zsh. In the manual page of that shell (man tcsh / man zshbuiltins), you can find the definition: where command (+) Reports all known instances of command, including aliases, builtins and executables in path. Therefore it is the tcsh-equivalent of the ...


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