tcsh

Generate a random filename in unix shell

梦想的初衷 提交于 2019-12-18 10:16:11
问题 I would like to generate a random filename in unix shell (say tcshell). The filename should consist of random 32 hex letters, e.g.: c7fdfc8f409c548a10a0a89a791417c5 (to which I will add whatever is neccesary). The point is being able to do it only in shell without resorting to a program. 回答1: Assuming you are on a linux, the following should work: cat /dev/urandom | tr -cd 'a-f0-9' | head -c 32 This is only pseudo-random if your system runs low on entropy, but is (on linux) guaranteed to

How to generate a core dump in Linux on a segmentation fault?

不问归期 提交于 2019-12-16 20:14:22
问题 I have a process in Linux that's getting a segmentation fault. How can I tell it to generate a core dump when it fails? 回答1: This depends on what shell you are using. If you are using bash, then the ulimit command controls several settings relating to program execution, such as whether you should dump core. If you type ulimit -c unlimited then that will tell bash that its programs can dump cores of any size. You can specify a size such as 52M instead of unlimited if you want, but in practice

csh script as executable does not setenv

China☆狼群 提交于 2019-12-14 02:15:44
问题 I am not able to set env variables through an executable csh/tcsh script An env variable set inside a csh/tcsh executable script "myscript" contents of the script ... setenv MYVAR /abc/xyz which is not able to set on the shell and reports "Undefined variable" I have made the csh/tcsh script as executable by the following shell command chmod +x /home/xx/bin/myscript also the path is updated to set path = (/home/xx/bin $path) which myscript /home/xx/bin/myscript When I run the script on command

Merge lines of two text files when PATTERN is found

女生的网名这么多〃 提交于 2019-12-12 20:03:02
问题 I am looking for an awk or sed solution to combine 2 files based on a matched pattern, like so: The PATTERN in this case is "cat". The number of lines in file 2 will always equal the number of pattern matches in file 1. File 1: I am a cat I am a dog I am a dog I am a cat I am a dog File 2: line 1 line 2 Merged File: I am a cat line 1 I am a dog I am a dog I am a cat line 2 I am a dog 回答1: Try this awk one liner: awk 'NR==FNR{a[NR]=$0;next}1;/cat/{print a[++i]}' file2 file1 test: $ cat file1 I

Enable History Logging In TCSH Shell

偶尔善良 提交于 2019-12-12 12:39:36
问题 How can I enable logging of all the commands entered in the tcsh shell? I've tried: Setting the $history variable to 100. The $savehist to 99. Set the $histfile to $home/.history Typing commands into the shell doesn't save the commands in the history file. 回答1: In my .tcshrc: set history=2000 set savehist=(2000 merge) 来源: https://stackoverflow.com/questions/3573095/enable-history-logging-in-tcsh-shell

tcsh: print date 2 weeks ago in shell

一世执手 提交于 2019-12-12 10:26:31
问题 In tcsh on OpenBSD, I need to print a date two weeks ago. E.g. if today is 2013-03-02 , I need to have 2013-02-16 printed out. 回答1: It doesn't seem like tcsh allows executing nested commands, so, it looks like ksh has to be used. date +%Y-%m-%d ; \ sh -c 'date -r $(expr $(date +%s) - $(expr 60 \* 60 \* 24 \* 14)) +%Y-%m-%d' 2013-03-02 2013-02-16 We get the date in the number of seconds since Epoch in UTC, and calculate two weeks in seconds with expr , subtract, and pass these seconds back to

tcsh scripting : regex in if statement

萝らか妹 提交于 2019-12-12 04:59:51
问题 what is the correct way to code this perl statment in tcsh shell script foreach (@array) { if (/^(pam|pom)/) { dosomething(); } } 回答1: Here's one way: #!/bin/tcsh -f set array = ( foo pam bar pom baz xpam pamx ) alias dosomething echo foreach elem ($array:q) if ($elem:q =~ {pam,pom}*) then dosomething $elem:q endif end Note that the expression on the right side of the =~ operator is a file matching pattern, not a regular expression, so this solution doesn't generalize to all cases. If you

How to find from within a csh script whether a certain command is available?

孤者浪人 提交于 2019-12-11 14:19:53
问题 In a csh script, I need to perform something only if a certain command is available. I wanted to do something like if( _WHAT_TO_PUT_HERE_ ) then # enter only if command "cmd" is in the path cmd ... endif how to do that in csh or tcsh? 回答1: I guess using the where command will solve your issue Check this: ~/animesh >where grep /bin/grep /tools/cfr/bin/grep ~/animesh >where egrep /bin/egrep /tools/cfr/bin/egrep ~/animesh >where xgrep ~/animesh > so lets say you are trying to find a command

Running a Git build inside a ClearCase View in tcsh

自作多情 提交于 2019-12-11 08:35:54
问题 I have a project stored in git that must be built outside of clearcase and then executed inside of a Clearcase view. All of the builds and execution must be done inside of tcsh due to restrictions on external scripts. The Clearcase view requires tcsh to successfully execute the commands. To automate this process, I would like to use jenkins. How is this possible? 回答1: I figured this out and wanted to record it somewhere. To execute a different shell inside of the Execute shell build step in