Table of Contents
- Bash/Tcsh Comparison Table
- How It Was Generated
- Makefile
- Generate HTML (genhtml.py)
- Bash Commands Script (compare.sh)
- Tcsh Commands Script (compare.csh)
Bash/Tcsh Comparison Table
The table below shows bash commands and their equivalents in tcsh along with the tools that I wrote to create it.
I put it together because I sometimes have to switch between shells and needed a handy reference. It was built up over time by as I came across tidbits that I wanted to remember.
In some cases there are different ways of doing the same thing so I simply chose my preferred approach (such as [[]] expressions rather than [] in the if statements).
I hope that you find it useful.
ID | Operation | bash | tcsh |
---|---|---|---|
1 | alias | alias foo=bar | alias foo bar |
2 | array: declaration | ARRAY=("a" "b" "c") | set ARRAY = ("a" "b" "c") |
3 | array: first item | echo first item [0] = ${ARRAY[0]} | echo "first item [1] = $ARRAY[1]" |
4 | array: iterate by index | for i in ${!ARRAY[@]}; do printf "%d %s\n" $i ${ARRAY[i]} done |
foreach i ( `seq $#ARRAY` ) echo $i $ARRAY[$i] |\ awk '{printf("%d %s\n",$1,$2);}' end |
5 | array: iterate by item | for item in ${ARRAY[@]} ; do echo item = $item done |
foreach item ( $ARRAY ) echo item = $item end |
6 | array: iterate by item, single line | A=("a" "b" "c") for x in ${A[@]} ; do echo $x; done |
N/A |
7 | array: size | echo ${#ARRAY[@]} items | echo $#ARRAY items |
8 | command substitution | # style 1 – can't be nested x=`ls –1` # style 2 – can be nested me=$(dirname –– $(readlink –f .)) echo $me |
# style 1 – can't be nested set x = `ls –1` # style 2 – not supported set r = `readlink –f .` set me = `dirname $r` echo $me |
9 | exit the shell | exit exit 1 |
exit exit 1 |
10 | formatted printing | # Native support. printf "%05d %s\n" 42 "Deep Thought" |
# No native support, # emulate with awk. # Embedded spaces are a pain. echo 42 "Deep Thought" |\ awk '{printf("%05d %s %s\n",$1,$2,$3);'} |
11 | function | function echo–cmds { echo "CMD : "$* # Echo the commands. local args="$@" # local var $args | sed –e 's/^/ /' } echo–cmds pwd echo–cmds ls –l |
N/A Can be emulated using external scripts |
12 | get shell name | echo $SHELL | echo $shell |
13 | get shell version | bash ––version echo $BASH_VERSION |
tcsh ––version echo $version |
14 | if/then/else: numeric | i=2 if (( i>2 )) ; then echo i greater than 2 elif (( i<2 )) ; then echo i less than 2 else echo i is two fi |
set i=2 if ($i>2) then echo i greater than 2 else if ($i<2) then echo i less than 2 else echo i is two endif |
15 | if/then/else: string | s="foo bar" if [[ "$s" == "foo bar" ]] ; then echo "foo" else echo "spam" fi |
set s="foo bar" if ("$s" == "foo bar") then echo "foo" else echo "spam" endif |
16 | include a file | source include–file . include–file |
source include–file |
17 | IO: redirect stderr | ls 2> /tmp/$$ | ( ls > /dev/tty ) >& /tmp/$$ |
18 | IO: redirect stdout | ls > /tmp/$$ | ls > /tmp/$$ |
19 | IO: redirect stdout and stderr | ls > /tmp/$$ 2>&1 # older ls &> /tmp/$$ # newer |
ls >& /tmp/$$ |
20 | job: move into the background | job <Ctrl–Z> bg |
job <Ctrl–Z> bg |
21 | job: move into the foreground | fg fg %1 |
fg fg %1 |
22 | job: start in the background | job & | job & |
23 | job: status | job echo status = $? |
job echo status = $? |
24 | local variable | function fct { local var='local' } |
# functions not supported |
25 | prompt | set PS1='\u >' # user name set PS1='\h >' # host set PS1='\! >' # command num #set PS1=N/A >' # last 3 dir parts set PS1='\W >' # last dir part set PS1='\w >' # curr dir full set PS1='\v >' # shell version set PS1='\u@\h \W (\!) >' |
set prompt='%n >' # user name set prompt='%j >' # host set prompt='! >' # command num set prompt='%c3 >' # last 3 dir parts set prompt='%c >' # last dir part set prompt='%~ >' # curr dir full #set prompt=N/A # shell version set prompt='%n@%j %c (!) >' |
26 | range iteration | for i in `seq 1000` ; do echo $i done for i in $( seq 1000 ) ; do # fastest |
foreach i ( `seq 1000` ) echo $i end |
27 | read values from the console | read –p "login? " login read –p "passwd? " –s passwd echo echo "login: $login" echo "passwd: $passwd" |
echo –n "login? " set login = $< echo –n "passwd? " echo |
28 | regex extension check | FILES=('f1.tar.bz2' 'f2.tar.gz' 'f3.zip') for FILE in ${FILES[@]} ; do if [[ "$FILE" =~ .tar.bz2$ ]] ; then echo "tar.bz2: $FILE" elif [[ "$FILE" =~ .tar.gz$ ]] ; then echo "tar.gz: $FILE" elif [[ "$FILE" =~ .zip$ ]] ; then echo "zip: $FILE" else echo "unk: $FILE" fi done |
set FILES=('f1.tar.bz2' 'f2.tar.gz' 'f3.zip') foreach FILE ( $FILES ) echo $FILE | grep '.tar.bz2$' >&/dev/null if ( $? == 0 ) then echo "tar.bz2: $FILE" continue endif echo $FILE | grep '.tar.gz$' >&/dev/null echo $FILE | grep '.zip$' >&/dev/null echo "unk: $FILE" |
29 | set path variable | export PATH="$PATH:/tmp" | set path = ( $path /tmp ) |
30 | set resource limits | ulimit | limit |
31 | setenv/export | export FOOBAR="spam" | setenv FOOBAR "spam" |
32 | switch statement | arg="foo" case "$arg" in "foo") echo "do foo" ;; "bar") echo "do bar" ;; "spam") echo "do spam" ;; *) echo "do be do be do" ;; esac |
set arg="foo" switch ("$arg") case "foo": echo "do foo" breaksw case "bar": echo "do bar" breaksw case "spam": echo "do spam" breaksw default: echo "do be do be do" breaksw endsw |
33 | variable: auto decrement | i=0 (( i–– )) echo auto deccrement = $i |
set i=0 @ i–– echo auto decrement = $i |
34 | variable: auto increment | i=0 (( i++ )) echo auto increment = $i |
set i=0 @ i++ echo auto increment = $i |
35 | variable: automatically exit on error | /bin/bash –e # invocation set –e # inside the shell |
/bin/tcsh –e # invocation only |
36 | variable: create array | ARRAY=("item1" "item2" "item2") | set ARRAY=("item1" "item2" "item2") |
37 | variable: create scalar | i=0 s="foo bar spam" |
set i=0 set="foo bar spam" |
38 | variable: debug tracing | set –x # on pwd set +x # off pwd |
set verbose # on pwd unset verbose # off pwd |
39 | variable: destroy or unset | ARRAY=("item1" "item2" "item2") unset ARRAY |
set ARRAY=("item1" "item2" "item2") unset ARRAY |
40 | variable: dump state | set | set |
41 | variable: dynamic | # Native support, can also use eval. a="some value" b=a echo $b = ${!b} bv="${!b}" echo bv = $bv |
# Not native, need to use eval. set a="some value" set b="a" eval "echo $b = "'$'${b} set bv=`eval echo '$'$b` echo bv = $bv |
42 | variable: print environment variables | env printenv |
env printenv |
43 | variable: substitution | foo='bar' echo ${foo/bar/baz/} |
set foo = 'bar' echo $foo:s/bar/baz/ |
44 | variable: turn on unset variable checking | set –u | N/A |
How It Was Generated
The table was generated automatically from two test scripts: a bash script (compare.sh) and a tcsh script (compare.csh). Each one ran all of the commands in the previous table.
I used another script (genhtml.py) to parse them and generate this table automatically under the control of a Makefile. See the comments in the python script for more
details about the record format. Here is how I ran it.
1 2 3 4 5 |
$ ls -l compare* -rwxr-xr-x 1 jlinoff staff 4306 Nov 20 22:03 compare.csh* -rwxr-xr-x 1 jlinoff staff 4214 Nov 20 22:04 compare.sh* $ make umask 0; ./genhtml.py compare.sh compare.csh >compare.html |
I then manually entered the HTML table data onto this page.
Makefile
This is the make file that I used.
1 2 3 4 5 6 7 8 9 |
# Generate the bash/tcsh comparison table. all: compare.html clean: rm -rf *~ *.html compare.html: genhtml.py compare.sh compare.csh umask 0; ./genhtml.py compare.sh compare.csh >$@ |
Generate HTML (genhtml.py)
This is the python script file that generated the HTML table data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
#!/usr/bin/env python ''' Read two shell files with specific formatting to parse out common records and produce and HTML table. It is used to extract the common records from a bash shell script file and tcsh shell script file. The idea is to create records in the bash and tcsh files with the same id so that this script can scoop them up and put them in a table. Records are surrounded by: # BEGIN: <id> <statements> # END The id can be any string but it must be the same in both files. Anything in between is printed. THe #@@ token is used to specify non-executing records. Here is a simple example: $ # ================================================================ $ # bash commands $ # ================================================================ $ cat compare.sh <<EOF #!/bin/bash # BEGIN: alias alias foo=bar # END # BEGIN: array: iterate by item, single line A=("a" "b" "c") for x in ${A[@]} ; do echo $x; done # END # BEGIN: array: iterate by index for i in ${!ARRAY[@]}; do printf "%d %s\n" $i ${ARRAY[i]} done # END EOF $ # ================================================================ $ # tcsh commands $ # ================================================================ $ cat compare.csh <<EOF # BEGIN: alias alias foo bar # END # BEGIN: array: iterate by item, single line #@@ N/A # END # BEGIN: array: iterate by index foreach i ( `seq $#ARRAY` ) echo $i $ARRAY[$i] |\ awk '{printf("%d %s\n",$1,$2);}' end # END EOF $ # ================================================================ $ # Generate the HTML. $ # ================================================================ $ ./genhtml.py compare.sh compare.csh > compare.html ''' import sys import os import re # ================================================================ # err # ================================================================ def err(msg): ''' Print an error message and exit. ''' print('ERROR: %s' % (msg)) sys.exit(1) # ================================================================ # err # ================================================================ def parse(fn): ''' Parse a shell script file looking for specific format instructions in the comments. ''' fp = open(fn,'r') rows = {} row = None n=0 for line in fp.readlines(): n += 1 line = line.rstrip() # begin m = re.search('^# BEGIN: (.+)$',line) if m: if row != None: err('missing END statement around line: %d in %s' % (n,fn)) title = m.group(1) if title in rows: err('duplicate entry "%s" at line %d in %s' % (title,n,fn)) row = {'title':title, 'file':fn, 'lineno':n, 'lines':[], } continue # end m = re.search('^# END',line) if m: rows[title]=row row = None continue # between begin and end, everything else is ignored if row: row['lines'].append(line) fp.close() return rows # ================================================================ # htmlize # ================================================================ def htmlize(line): ''' HTMLize a string. ''' line = line.replace('&','&') line = line.replace('"','"') line = line.replace("'",''') line = line.replace('<','<') line = line.replace('>','>') line = line.replace(' ',' ') line = line.replace('`','`') line = line.replace('-','–') return line # ================================================================ # myprint # ================================================================ def myprint(m): ''' Write a string to stdout. ''' sys.stdout.write(str(m)) # ================================================================ # cell # ================================================================ def cell(indent, rec): ''' Write out a column cell. ''' myprint('%s<td class="mycell-code">' % (indent)) first=True for line in rec['lines']: if not first: myprint('<br />') first = False line = line.replace('#@@ ','') myprint(htmlize(line)) myprint('</td>\n') # ================================================================ # gencss # ================================================================ def gencss(): ''' Generate the CSS styling information specifically for wordpress. ''' css =''' <style type="text/css"> table.mytable { font-family: Arial, Helvetica; font-size: 1.2em; border-collapse: separate; border-spacing: 1px; *border-collapse: expression('separate', cellSpacing = '1px'); border: 2px solid lightgray; } tr.myrow-even { vertical-align: top; background-color: #ffffea; border: 2px solid lightgray; } tr.myrow-odd { vertical-align: top; background-color: none; border: 2px solid lightgray; } th.mycell-hdr { vertical-align: top; text-align: center; padding: 4px 4px; border: 2px solid lightgray; /*font-size: 1.3em;*/ } td.mycell-id { vertical-align: top; text-align: right; padding: 2px 2px; border: 1px solid lightgray; font-size: 0.9em; line-height: 100%; } td.mycell-title { vertical-align: top; text-align: left; padding: 2px 2px; border: 1px solid lightgray; font-size: 0.9em; line-height: 100%; } td.mycell-code { vertical-align: top; font-family: "Courier New", monospace; text-align: left; padding: 2px 2px; border: 1px solid lightgray; font-size: 0.9em; line-height: 100%; } div#mydiv { margin-left: -30px; width: 110%; } </style> ''' return css # ================================================================ # main # ================================================================ def main(): ''' Main entry point. ''' # This is a simple script, no need for fancy argument handling. assert len(sys.argv) == 3 bash_shell = sys.argv[1] tcsh_shell = sys.argv[2] bash_recs = parse(bash_shell) tcsh_recs = parse(tcsh_shell) if len(bash_recs) != len(tcsh_recs): err('Mismatched number of records: %d != %d' % (len(bash_recs), len(tcsh_recs))) for title in sorted(bash_recs): if title not in tcsh_recs: err('missing entry "%s"' % (title)) myprint(gencss()) print ''' <div id="mydiv"> <table> <thead> <tr bgcolor="#DDDDDD"> <th class="mycell-hdr">ID</th> <th class="mycell-hdr">Operation</th> <th class="mycell-hdr">bash</th> <th class="mycell-hdr">tcsh</th> </tr> </thead> <tbody> ''' tr_indent = ' ' td_indent = tr_indent + ' ' i=0 for title in sorted(bash_recs, key=lambda x: x.lower()): bash_rec=bash_recs[title] tcsh_rec=tcsh_recs[title] if (i%2) == 0: myprint('%s<tr class="myrow-even">\n' % (tr_indent)) else: myprint('%s<tr class="myrow-odd">\n' % (tr_indent)) myprint('%s<td class="mycell-id">%d</td>\n' % (td_indent, i+1)) myprint('%s<td class="mycell-title">%s</td>\n' % (td_indent, title)) cell(td_indent, bash_rec) cell(td_indent, tcsh_rec) myprint('%s</tr>\n' % (tr_indent)) i += 1 print ''' </tbody> </table> </div> ''' if __name__ == '__main__': main() |
Bash Commands Script (compare.sh)
This is the script that tested the bash commands.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
#!/bin/bash # BEGIN: alias alias foo=bar # END # BEGIN: array: declaration ARRAY=("a" "b" "c") # END # BEGIN: array: size echo ${#ARRAY[@]} items # END # BEGIN: array: first item echo first item [0] = ${ARRAY[0]} # END # BEGIN: array: iterate by item for item in ${ARRAY[@]} ; do echo item = $item done # END # BEGIN: array: iterate by item, single line A=("a" "b" "c") for x in ${A[@]} ; do echo $x; done # END # BEGIN: array: iterate by index for i in ${!ARRAY[@]}; do printf "%d %s\n" $i ${ARRAY[i]} done # END # BEGIN: variable: create scalar i=0 s="foo bar spam" # END # BEGIN: variable: create array ARRAY=("item1" "item2" "item2") # END # BEGIN: variable: destroy or unset ARRAY=("item1" "item2" "item2") unset ARRAY # END # BEGIN: variable: auto increment i=0 (( i++ )) echo auto increment = $i # END # BEGIN: variable: auto decrement i=0 (( i-- )) echo auto deccrement = $i # END # BEGIN: function function echo-cmds { echo "CMD : "$* # Echo the commands. local args="$@" # local var $args | sed -e 's/^/ /' } echo-cmds pwd echo-cmds ls -l # END # BEGIN: job: start in the background #@@ job & # END # BEGIN: job: move into the background #@@ job #@@ <Ctrl-Z> #@@ bg # END # BEGIN: job: status #@@ job #@@ echo status = $? # END # BEGIN: variable: debug tracing set -x # on pwd set +x # off pwd # END # BEGIN: variable: dump state set # END # BEGIN: variable: turn on unset variable checking set -u # END set +u # BEGIN: variable: automatically exit on error #@@ /bin/bash -e # invocation set -e # inside the shell # END set +e # BEGIN: variable: print environment variables env printenv # END # BEGIN: variable: dynamic # Native support, can also use eval. a="some value" b=a echo $b = ${!b} bv="${!b}" echo bv = $bv # END # BEGIN: IO: redirect stdout ls > /tmp/$$ # END # BEGIN: IO: redirect stderr ls 2> /tmp/$$ # END # BEGIN: IO: redirect stdout and stderr ls > /tmp/$$ 2>&1 # older ls &> /tmp/$$ # newer # END # BEGIN: exit the shell #@@ exit #@@ exit 1 # END # BEGIN: job: move into the foreground #@@ fg #@@ fg %1 # END # BEGIN: formatted printing # Native support. printf "%05d %s\n" 42 "Deep Thought" # END # BEGIN: if/then/else: numeric i=2 if (( i>2 )) ; then echo i greater than 2 elif (( i<2 )) ; then echo i less than 2 else echo i is two fi # END # BEGIN: if/then/else: string s="foo bar" if [[ "$s" == "foo bar" ]] ; then echo "foo" else echo "spam" fi # END # BEGIN: include a file #@@ source include-file #@@ . include-file # END # BEGIN: set resource limits #@@ ulimit # END # BEGIN: set path variable export PATH="$PATH:/tmp" # END # BEGIN: get shell name echo $SHELL # END # BEGIN: get shell version bash --version echo $BASH_VERSION # END # BEGIN: switch statement arg="foo" case "$arg" in "foo") echo "do foo" ;; "bar") echo "do bar" ;; "spam") echo "do spam" ;; *) echo "do be do be do" ;; esac # END # BEGIN: read values from the console read -p "login? " login read -p "passwd? " -s passwd echo echo "login: $login" echo "passwd: $passwd" # END # BEGIN: prompt set PS1='\u >' # user name set PS1='\h >' # host set PS1='\! >' # command num #set PS1=N/A >' # last 3 dir parts set PS1='\W >' # last dir part set PS1='\w >' # curr dir full set PS1='\v >' # shell version set PS1='\u@\h \W (\!) >' # END # BEGIN: regex extension check FILES=('f1.tar.bz2' 'f2.tar.gz' 'f3.zip') for FILE in ${FILES[@]} ; do if [[ "$FILE" =~ .tar.bz2$ ]] ; then echo "tar.bz2: $FILE" elif [[ "$FILE" =~ .tar.gz$ ]] ; then echo "tar.gz: $FILE" elif [[ "$FILE" =~ .zip$ ]] ; then echo "zip: $FILE" else echo "unk: $FILE" fi done # END # BEGIN: command substitution # style 1 - can't be nested x=`ls -1` # style 2 - can be nested me=$(dirname -- $(readlink -f .)) echo $me # END # BEGIN: local variable function fct { local var='local' } # END # BEGIN: range iteration for i in `seq 1000` ; do echo $i done for i in $( seq 1000 ) ; do echo $i done # fastest for i in {1..1000} ; do echo $i done # END # BEGIN: setenv/export export FOOBAR="spam" # END # BEGIN: variable: substitution foo='bar' echo ${foo/bar/baz/} # END |
Tcsh Commands Script (compare.csh)
This is the script that tested the tcsh commands.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
#!/bin/tcsh # BEGIN: alias alias foo bar # END # BEGIN: array: declaration set ARRAY = ("a" "b" "c") # END # BEGIN: array: size echo $#ARRAY items # END # BEGIN: array: first item echo "first item [1] = $ARRAY[1]" # END # BEGIN: array: iterate by item foreach item ( $ARRAY ) echo item = $item end # END # BEGIN: array: iterate by item, single line #@@ N/A # END # BEGIN: array: iterate by index foreach i ( `seq $#ARRAY` ) echo $i $ARRAY[$i] |\ awk '{printf("%d %s\n",$1,$2);}' end # END # BEGIN: variable: create scalar set i=0 set="foo bar spam" # END # BEGIN: variable: create array set ARRAY=("item1" "item2" "item2") # END # BEGIN: variable: destroy or unset set ARRAY=("item1" "item2" "item2") unset ARRAY # END # BEGIN: variable: auto increment set i=0 @ i++ echo auto increment = $i # END # BEGIN: variable: auto decrement set i=0 @ i-- echo auto decrement = $i # END # BEGIN: function #@@ N/A #@@ Can be emulated using #@@ external scripts # END # BEGIN: job: start in the background #@@ job & # END # BEGIN: job: move into the background #@@ job #@@ <Ctrl-Z> #@@ bg # END # BEGIN: job: move into the foreground #@@ fg #@@ fg %1 # END # BEGIN: job: status #@@ job #@@ echo status = $? # END # BEGIN: variable: debug tracing set verbose # on pwd unset verbose # off pwd # END # BEGIN: variable: dump state set # END # BEGIN: variable: turn on unset variable checking #@@ N/A # END # BEGIN: variable: automatically exit on error #@@ /bin/tcsh -e # invocation only # END # BEGIN: variable: print environment variables env printenv # END # BEGIN: variable: dynamic # Not native, need to use eval. set a="some value" set b="a" eval "echo $b = "'$'${b} set bv=`eval echo '$'$b` echo bv = $bv # END # BEGIN: IO: redirect stdout ls > /tmp/$$ # END # BEGIN: IO: redirect stderr ( ls > /dev/tty ) >& /tmp/$$ # END # BEGIN: IO: redirect stdout and stderr ls >& /tmp/$$ # END # BEGIN: exit the shell #@@ exit #@@ exit 1 # END # BEGIN: formatted printing # No native support, # emulate with awk. # Embedded spaces are a pain. echo 42 "Deep Thought" |\ awk '{printf("%05d %s %s\n",$1,$2,$3);'} # END # BEGIN: if/then/else: numeric set i=2 if ($i>2) then echo i greater than 2 else if ($i<2) then echo i less than 2 else echo i is two endif # END # BEGIN: if/then/else: string set s="foo bar" if ("$s" == "foo bar") then echo "foo" else echo "spam" endif # END # BEGIN: include a file #@@ source include-file # END # BEGIN: set resource limits #@@ limit # END # BEGIN: set path variable set path = ( $path /tmp ) # END # BEGIN: get shell name echo $shell # END # BEGIN: get shell version tcsh --version echo $version # END # BEGIN: switch statement set arg="foo" switch ("$arg") case "foo": echo "do foo" breaksw case "bar": echo "do bar" breaksw case "spam": echo "do spam" breaksw default: echo "do be do be do" breaksw endsw # END # BEGIN: read values from the console echo -n "login? " set login = $< echo -n "passwd? " stty -echo set passwd = $< stty echo echo echo "login: $login" echo "passwd: $passwd" # END # BEGIN: prompt set prompt='%n >' # user name set prompt='%j >' # host set prompt='! >' # command num set prompt='%c3 >' # last 3 dir parts set prompt='%c >' # last dir part set prompt='%~ >' # curr dir full #set prompt=N/A # shell version set prompt='%n@%j %c (!) >' # END # BEGIN: regex extension check set FILES=('f1.tar.bz2' 'f2.tar.gz' 'f3.zip') foreach FILE ( $FILES ) echo $FILE | grep '.tar.bz2$' >&/dev/null if ( $? == 0 ) then echo "tar.bz2: $FILE" continue endif echo $FILE | grep '.tar.gz$' >&/dev/null if ( $? == 0 ) then echo "tar.gz: $FILE" continue endif echo $FILE | grep '.zip$' >&/dev/null if ( $? == 0 ) then echo "zip: $FILE" continue endif echo "unk: $FILE" end # END # BEGIN: command substitution # style 1 - can't be nested set x = `ls -1` # style 2 - not supported set r = `readlink -f .` set me = `dirname $r` echo $me # END # BEGIN: local variable # functions not supported # END # BEGIN: range iteration foreach i ( `seq 1000` ) echo $i end # END # BEGIN: setenv/export setenv FOOBAR "spam" # END # BEGIN: variable: substitution set foo = 'bar' echo $foo:s/bar/baz/ # END |
Nice table – useful for when I have to VNC to check out a problem and they’re using csh/tcsh. Only thing I can see missing is export(bash) / setenv(csh) as a ‘set’ in csh will not export a new variable. (So your path example is OK as it’s a pre-existing environment/exported variable).
Thank you. I will add setenv/export today.
Added command substitution and expanded the table a bit.
Best blog…..I spend time many times searching google when working b/w these two terminals….this is all at one place..sorted down very well.
Thanks bro….
tcsh recognizes command line arguments in the array argv[ ] , BASH doesn’t recognize this.
Bash does have access the command line arguments but it doesn’t name them argv.
Are you suggesting that an entry is added that shows this in bash:
and something like this in tcsh:
What about adding bash “parameter expansion” / tcsh “variable substitution”? Eg in bash you write “${foo/bar/baz/}” where in tcsh you would write “$foo:s/bar/baz/”
Thanks for a great resource.
Thank you for the suggestion. It has been added as “variable: substitution”, entry 43.
That’s very useful thank you!
Life saver . THANKS !!!!!! Wonderful !!
Could you please upload your tcsh and bash script as well as the python script you used to generate the tables so that everyone can easily create their own version of this table with their frequently used commands?
Sure but I have to find them first. I will upload them in the near future.
I have added the tools that I wrote to create the table. I hope that you find it helpful.
There are a few tcsh things I don’t know how to do in bash that have kept me from switching, e.g.:
Any of these you could add?
Thank you. This is excellent feedback. I will take a look.