Tag Info

Hot answers tagged

9

Dennis points out the usual alternatives in his answer (single-in-double, double-in-single, single quoted strings concatenated with escaped single quotes; you already mentioned Perl's customizable quote operators), but maybe this is the direct answer you were looking for. In Bourne-like shells (sh, ksh, ash, dash, bash, zsh, etc.) single quoted strings are ...


9

In Bash shell: export FOO="/a/b/c" And you don't want to use $path. That's a special variable.


8

you can either user screen or nohup if you choose screen : launch screen before you run your service: $ screen and then, run your service inside of the screen: ./MyProg.sh > myprog.log ( or anything you want here ). and then Ctrl+a d when you came back, just: $ screen -r for more information: http://www.gnu.org/s/screen/ about the nohup : ...


7

Use -path instead of -name: find directory_to_search -path "*/dir1/dir2/reqdfile" Note that there's only one asterisk.


7

The ~ (tilde) is a quick way of specifying your home directory. The ~/.somefilename means your home directory, the file .somefilename.


6

The time command built-in to the C shell (csh or tcsh) doesn't work with pipelines. To avoid this limitation, use the standalone time command instead, which is usually found at /usr/bin/time (if it isn't, try whereis time to locate it). Change time in your command-line to /usr/bin/time (or /usr/bin/time -p) or whatever the path to the time program is, and ...


6

Aha, FreeBSD. That's tcsh, I believe. So: set path=(/sbin $path)


6

The problem is that ` marks are used to denote commands who's output should be substituted in your command... so your command is actually three commands: "echo " (contained in the first set of 1 marks) "-1308741881 | bc" (contained in the second set of 1 marks) find . -mtime -OUTPUT FROM COMMAND #1date +%sOUTPUT FROM COMMAND #2 Command #1 outputs ...


6

assuming you really want csh/tcsh syntax (as you have tagged your question), put this setenv P1 "/a/b/c/d/e/f" to your .tcshrc after that you are able to do cd $P1


6

It's not likely that you need your variable in the environment. So, in csh instead of setenv, you can do: set dir="/a/b/c/d/e/f" cd $dir or in Bash, instead of export: dir="/a/b/c/d/e/f" cd $dir


6

For me, all your examples produce: Hello, world! And so does this: perl -e 'print "Hello, world!", "\n";' And this: perl -e 'print '\''Hello, world!'\'', "\n";' Can you clarify what it is you're trying to do? In the shell, such as Bash, if you want to print quotation marks as part of the string, one type of quotes escapes the other. $ echo ...


5

Don't try to make the same script portable between two completely different shells. Even compatibility of sh and bash is hard to achieve, and those use the same syntax... (I can't even imagine how one can stand csh in the first place.) Write your settings scriptlet like this: test "$?BASH_VERSION" = "0" || eval 'setenv() { export "$1=$2"; }' setenv ...


4

Short answer: the SHELL environment variable represents the default shell for your user profile, not the shell you are currently talking to. It is used by programs that spawn subshells. Alternately, check your .cshrc for an exec bash command. I used to do that at a site where users were not allowed to change their default shell from csh.


4

csh/tcsh you say? setenv PATH ${PATH}:/my/additional/path Update: Fixed my error of forgetting to escape the colon. Thanks Dennis.


4

The tilde ~ character is interpreted by most shells as the "home directory" for you. The "." doesn't mean anything if it's part of a filename, although some programs such as ls will (unless explicitely told otherwise) not show files if their name starts with a "dot". Sort of a "hidden" attribute.


4

Well, it's not an alias, you can use vim like this: vim +<LineNumberHere> fileName So, for example vim +150 .bash_history opens your .bash_history file (for bash), and navigates to line 150. Incidentally, you can also do this with search terms. For example vim +/MyTerm MyFile opens MyFile and navigates to the first occurrence of MyTerm from ...


4

One solution to this is to use the file_line.vim plugin, which lets you specify a file name and line number as an argument to Vim or on Vim's command line, just as you've shown. Another is this script, $ cat $(which vimgrep) #!/bin/bash tmp=$(mktemp) cat > $tmp exec < /dev/tty vim --cmd 'let &efm=&gfm' -q $tmp "$@" rm $tmp which can be used like ...


3

You should be able to do this by rebinding the arrow keys in your bash profile. By default the up- and down- arrows are bound to previous-history and next-history; I believe the behaviour you seek is history-search-backward and history-search-forward, which be default are not bound to any key. The following commands will do the rebinding: bind '"\e[A": ...


3

You can start vim with a configuration file other than ~/.vimrc by using the -u option like this: vim -N -u ~acheong/.vimrc To avoid typing that each time, you could define an alias for it each time you log in to one of those accounts: alias vim='vim -N -u ~acheong/.vimrc' See :help -u :help initialization


3

You could try and install Cygwin, this will give you a relatively complete Linux environment within Windows. You can configure it to install just what you need (like a shell and a few utilities, and vi or emacs), and go from there.


3

I like using notepad++. It has an EOL (end of line) converter under Edit...EOL (details).


3

Use export. export your_path="/a/b/c/d/e/f" cd $your_path If you want it to persist through logins, you're going to need to edit it into your .profile file.


3

Most shells (tcsh, bash, zsh, but not csh) increment the SHLVL environment variable when they start, so that $SHLVL indicates the level of nesting of your current shell. So do something like (for tcsh) set xt_bg_colors=(white white black green) set xt_fg_colors=(black black gray yellow) alias xt "xterm -geometry 105x25 -font 8x13 -bc -bg ...


2

Use if ( "x$R" == "x" ) then echo empty else echo not empty endif The C shell doesn't have an empty operator like bash. Also, you can't quote with ' as it will prevent the variable expansion.


2

It is best to avoid aliases for anything other than simple, one-command substitutions. To use arguments, multiple commands, etc., you can define a function, accessing parameters the same way you would in a script: foo() { do_this do_that "$1" } cat() { command cat "$@" && echo ""; } (Normally functions override executables, so command cat ...


2

Instead of using \!:1 to select the first argument, use \!* to select all the arguments. This works fine for there being no arguments. It will throw a wobbly if you provide more than one argument though.


2

The following code solved both of my problems. set prompt="\n%{\033[0;32m%}%n@%m:%{\033[0;33m%}%~%{\033[1;30m%}>%{\033\[1;37m%} "


2

scp isn't the issue. The problem is in the way the two shells handle curly braces. csh% echo root@1.2.3.4:/{/root/install.log} root@1.2.3.4://root/install.log bash$ echo root@1.2.3.4:/{/root/install.log} root@1.2.3.4:/{/root/install.log} Why do you want the curly braces anyway?


2

sounds like cwdcmd is set (man tcsh): Runs after every change of working directory.


2

in ~/.cshrc put set filec set autolist



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