csh

How can I check if a variable is empty or not in tcsh Shell?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 22:10:29
IF I have to check that if a variable is empty or not for that in bash shell i can check with the following script: if [ -z "$1" ] then echo "variable is empty" else echo "variable contains $1" fi But I need to convert it into tcsh shell. The standard warnings regarding use of tcsh / csh apply, but here's the translation: if ( "$1" == "" ) then # parentheses not strictly needed in this simple case echo "variable is empty" else echo "variable contains $1" endif Note, though, that if you were to use an arbitrary variable name rather than $1 in the above, the statement would break if that

Ctrl-R to search backwards for shell commands in csh

£可爱£侵袭症+ 提交于 2019-12-03 10:50:14
问题 I love this shortcut in borne shell, and want to find out if it is possible to simulate and/or have (perhaps to install an add-on or with a script) it in csh or tsch thanks 回答1: Something that csh, tcsh, and even bash have is the cool ! history substitution . % !cc This will run the last command starting with cc % cc !* That supplies the parameters from the last command. % g++ !cc:* That finds the last command that started with cc and substitutes its parameters % !?hello.c This finds the last

How to add date string to each line of a continuously written log file

依然范特西╮ 提交于 2019-12-03 06:19:10
问题 Having a long running program that continuously writes to a logfile - how is it possible, disregarding any buffering issues, to add a date string to each line written to that file using a linux script? I would imagine something like this: tail -f logfile | ADD_DATE_TO_EACH_LINE > logfile2 The input would be something like that: abc def ghi jkl The output should be similar to that: 2011-06-16 18:30:59 abc 2011-06-16 18:31:00 def 2011-06-16 18:35:21 ghi 2011-06-16 18:40:15 jkl 回答1: With perl:

bash vs csh vs others - which is better for application maintenance? [duplicate]

烈酒焚心 提交于 2019-12-03 02:08:52
This question already has answers here : What Linux shell should I use? [closed] (19 answers) Possible Duplicate: What Linux shell should I use? I am starting to get proficient in a Linux environment and i'm trying to pick a weapon of choice in terms of command shell scripting (as i'm still a big n00b at this) that will help me (and others) manage, test and administer a set of server side applications running on a *NIX environment. My question is: What is(are) the preferred command shell(s) out there when the following criteria are considered: How easy is it to learn/understand for a junior

Ctrl-R to search backwards for shell commands in csh

孤者浪人 提交于 2019-12-03 01:19:29
I love this shortcut in borne shell, and want to find out if it is possible to simulate and/or have (perhaps to install an add-on or with a script) it in csh or tsch thanks DigitalRoss Something that csh, tcsh, and even bash have is the cool ! history substitution . % !cc This will run the last command starting with cc % cc !* That supplies the parameters from the last command. % g++ !cc:* That finds the last command that started with cc and substitutes its parameters % !?hello.c This finds the last command that had hello.c anywhere in it. Try bindkey "^R" i-search-back 来源: https:/

How to color a prompt on FreeBSD/cshrc?

心不动则不痛 提交于 2019-12-03 00:19:07
I'm being put in charge of managing a bunch of servers, I want to set up my prompts on each of them so that I don't get confused as to where I am logged in to. I've edited my .cshrc files and put this in them: set prompt=`whoami`@`hostname -s`:$cwd'$ ' But I'd like to color that prompt so it stands out a bit more. Maybe green with white text or something. How can I do that? I'm not very familiar with the shell syntax. I'm SSH-ing in from the standard terminal that comes with Ubuntu, if that's relevant. mpen This page has a pretty good explanation, although the syntax is a bit different in csh

How to add date string to each line of a continuously written log file

空扰寡人 提交于 2019-12-02 19:44:57
Having a long running program that continuously writes to a logfile - how is it possible, disregarding any buffering issues, to add a date string to each line written to that file using a linux script? I would imagine something like this: tail -f logfile | ADD_DATE_TO_EACH_LINE > logfile2 The input would be something like that: abc def ghi jkl The output should be similar to that: 2011-06-16 18:30:59 abc 2011-06-16 18:31:00 def 2011-06-16 18:35:21 ghi 2011-06-16 18:40:15 jkl With perl: command 2>&1 | perl -pe 'print scalar(localtime()), " ";' With gawk: command 2>&1 | awk '{ print strftime(),

Display only files and folders that are symbolic links in tcsh or bash

我们两清 提交于 2019-12-02 15:48:27
Basically I want do the following: ls -l[+someflags] (or by some other means) that will only display files that are symbolic links so the output would look -rw-r--r-- 1 username grp size date-time filename -> somedir -rw-r--r-- 1 username grp size date-time filename2 -> somsdfsdf etc. For example, to show only directories I have an alias: alias lsd 'ls -l | grep ^d' I wonder how to display only hidden files or only hidden directories? I have the following solution, however it doesn't display the output in color :( ls -ltra | grep '\->' ChristopheD Find all the symbolic links in a directory: ls

csh script: check if command exists

混江龙づ霸主 提交于 2019-12-02 09:15:38
问题 I would like to have something like this if (command_not_exists) exit Can someone tell me how to achieve this functionality in a cshell script? 回答1: My problem is solved using where command (I was trying with which command). Solution: if(`where test_cmd` == "") then printf "\ntest_cmd: Command not found\n"; exit(1); endif Thanks 来源: https://stackoverflow.com/questions/22040308/csh-script-check-if-command-exists

why is a double-quoted awk command substitution failing in csh

落花浮王杯 提交于 2019-12-02 08:55:07
Using C shell, the following command-line set pf = "`awk -v var=$pd '{if($1<0) print var, $2, $3}' test.txt`" returns an error in awk: awk: {if( <0) print var, , } syntax error. This is especially puzzling as the command itself works without any problem: awk -v var=$pd '{if($1<0) print var, $2, $3}' test.txt Is there a way that we can store all output of the single Awk command line into a single variable? What is the reason the above is failing? After some tinkering, I can only come to the conclusion that it is one of those C-Shell quirks. C-shell ( csh or tcsh ) is apparently notoriously