| Task | bash | CMD.EXE |
|---|---|---|
| Change directory | cd |
cd |
| Display current working directory | pwd |
cd |
Create text file from console
|
$ cat >test.txt This is a test This is line 2 ^D $ |
C:\> copy con test.txt This is a test This is line 2 ^Z 1 file(s) copied. C:\> |
| Echo contents of text file to console |
$ cat test.txt This is a test This is line 2 $ |
C:\> type test.txt This is a test This is line 2 C:\> |
| Set an environment variable |
$ MY_VAR=TEST $ |
C:\> set MY_VAR=TEST C:\> |
| Echo value of environment variable to console |
$ echo $MY_VAR TEST $ |
C:\> echo %MY_VAR% TEST C:\> |
| Append directory to end of PATH variable |
PATH=$PATH:~/csci142/lab3
|
PATH %PATH%;d:\csci142\lab3
|
List contents of directory:
|
|
|
| List environment variables | set |
set |
| Clear console screen |
<Ctrl-L>
clear
|
cls
|
Command recall
|
<Ctrl-P>,
<Ctrl-N>
Up-arrow,
Down-arrow
|
Up-arrow,
Down-arrow
|
| Echo command history to console |
history
cat ~/.bash_history
|
doskey /h
|
| Alias / keyboard macro |
alias NAME=command
|
doskey NAME=command
|
Perl "one liner"
|
$ perl -e 'print "Hello World\n";' Hello World $ |
|
C:\> perl -e "print \"Hello World\n\";" Hello World C:\> |
||
|
Executable Perl script Windows Notes:
|
$ cat hello #!/usr/bin/perl # hello # UNIX executable Perl script # Set file attributes/permissions # as follows: -rwxr--r-- # # $ chmod 744 hello print "Hello, World!\n"; # --------- end of hello --------- $ chmod 744 hello $ ./hello Hello, World! $ |
C:\> type hello.bat @echo off :: hello.bat :: Windows executable Perl script :: Note: :: assumes perl.exe is in path :: otherwise, use absolute path perl -x -S "%0" %* goto end #!perl print "Hello, World!\n"; __END__ :end :: ------ end of hello.bat ------ C:\> hello Hello, World! |
|
www.mhuffman.com/notes/dos/bash_cmd.htm Mike Huffman: |