Translate between bash and tcsh commands

Table of Contents

  1. Bash/Tcsh Comparison Table
  2. How It Was Generated
  3. Makefile
  4. Generate HTML (genhtml.py)
  5. Bash Commands Script (compare.sh)
  6. 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
    echo $i
done

# fastest
for i in {1..1000} ; do
    echo $i
done

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? "
stty –echo
set passwd = $<
stty echo

echo
echo "login: $login"
echo "passwd: $passwd"

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
    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

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.

[crayon lang=”bash” toolbar=”always” title=”script”]
$ 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
[/crayon]

I then manually entered the HTML table data onto this page.

Makefile

This is the make file that I used.

[crayon lang=”make” toolbar=”always” title=”Makefile”]
# 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 >$@
[/crayon]

Generate HTML (genhtml.py)

This is the python script file that generated the HTML table data.

[crayon lang=”python” toolbar=”always” title=”genhtml.py”]
#!/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:

# 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 < 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

‘ % (indent))
first=True
for line in rec[‘lines’]:
if not first:
myprint(‘
‘)
first = False
line = line.replace(‘#@@ ‘,”)
myprint(htmlize(line))

myprint(‘

\n’)

# ================================================================
# gencss
# ================================================================
def gencss():
”’
Generate the CSS styling information specifically for
wordpress.
”’

css =”’

”’
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 ”’

”’
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

\n’ % (tr_indent))
else:
myprint(‘%s

\n’ % (tr_indent))
myprint(‘%s

\n’ % (td_indent, i+1))
myprint(‘%s

\n’ % (td_indent, title))
cell(td_indent, bash_rec)
cell(td_indent, tcsh_rec)
myprint(‘%s

\n’ % (tr_indent))
i += 1

print ”’

ID Operation bash tcsh
%d %s

”’

if __name__ == ‘__main__’:
main()
[/crayon]

Bash Commands Script (compare.sh)

This is the script that tested the bash commands.

[crayon lang=”bash” toolbar=”always” title=”compare.sh”]
#!/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
#@@
#@@ 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
[/crayon]

Tcsh Commands Script (compare.csh)

This is the script that tested the tcsh commands.

[crayon lang=”tcsh” toolbar=”always” title=”compare.ch”]
#!/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
#@@
#@@ 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
[/crayon]

18 thoughts on “Translate between bash and tcsh commands”

  1. 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).

  2. 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….

    1. 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:

      #!/bin/bash
      
      argv=$*
      argc=$#
      
      echo argc = $argc
      echo argv = $argv
      
      for arg in ${argv[@]} ; do
          echo $arg
      done
      

      and something like this in tcsh:

      #!/bin/tcsh
      
      set argc = $#argv
      
      echo $argc
      echo $argv
      
      foreach arg ($argv)
          echo $arg
      end
      
  3. 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.

  4. 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?

  5. There are a few tcsh things I don’t know how to do in bash that have kept me from switching, e.g.:

    set history = 2048
    set savehist = (2048 merge)
    set autolist				#  lists possibilities when completion is ambiguous
    set autoexpand				#  expands history substitutions, e.g. try this with it set and unset:  cat !$
    set autocorrect				#  tries to correct your misspellings, e.g. try this with it set and unset:  /uzr/bin
    set correct = cmd			# does autocorrect correct only commands, or more?  see man tcsh for more info
    set matchbeep=nomatch
    set symlinks=chase
    set rmstar					# warn if user types "rm *"
    set histdup=erase			# all = only unique entries are added to history; prev = cmd only added if not the same as previous entry; erase = cmd added and previous identical entries are erased
    set complete=enhance		# autocompletion ignores case, considers periods/hyphens/underscores to be word separators, and hyphens and underscores to be equivalent
    complete cd  	p/1/d/		# autocomplete with directories only
    complete man	'p/*/c/'	# autocomplete with commands only
    set fignore = ( .o )		# filename suffixes to be ignored by shell auto-completion
    bindkey    ^[[3~  delete-char		# for x
    alias cwdcmd 'pwd; ls'
    alias precmd 'printf "33]7;%s\a" "file://$HOST$cwd:ags/ /%20/"'
    alias b1 'n `/bin/ls -1 \!* | head -1`'
    alias fae 'n `which \!*`'
    

    Any of these you could add?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.