Penukaran basic DOS Batch
Nukar DOS Batch file ke Shell scripts pakei *nix
Jadual kat dibah tok Batch file pakei keywords / variables /operators ngan persamaan makei shell.
Batch File Operator | Shell Script Equivalent | Meaning |
---|---|---|
% | $ | command-line parameter prefix |
/ | - | command option flag |
\ | / | directory path separator |
== | = | (equal-to) string comparison test |
!==! | != | (not equal-to) string comparison test |
| | | | pipe |
@ | set +v | do not echo current command |
* | * | filename "wild card" |
> | > | file redirection (overwrite) |
>> | >> | file redirection (append) |
< | < | redirect stdin |
%VAR% | $VAR | environmental variable |
REM | # | comment |
NOT | ! | negate following test |
NUL | /dev/null | "black hole" for burying command output |
ECHO | echo | echo (many more option in Bash) |
ECHO. | echo | echo blank line |
ECHO OFF | set +v | do not echo command(s) following |
FOR %%VAR IN (LIST) DO | for var in [list]; do | "for" loop |
:LABEL | none (unnecessary) | label |
GOTO | none (use a function) | jump to another location in the script |
PAUSE | sleep | pause or wait an interval |
CHOICE | case or select | menu choice |
IF | if | if-test |
IF EXIST FILENAME | if [ -e filename ] | test if file exists |
IF !%N==! | if [ -z "$N" ] | if replaceable parameter "N" not present |
CALL | source or . (dot operator) | "include" another script |
COMMAND /C | source or . (dot operator) | "include" another script (same as CALL) |
SET | export | set an environmental variable |
SHIFT | shift | left shift command-line argument list |
SGN | -lt or -gt | sign (of integer) |
ERRORLEVEL | $? | exit status |
CON | stdin | "console" (stdin) |
PRN | /dev/lp0 | (generic) printer device |
LPT1 | /dev/lp0 | first printer device |
COM1 | /dev/ttyS0 | first serial port |
DOS commands ngan persamaan UNIX
DOS Command | UNIX Equivalent | Effect |
---|---|---|
ASSIGN | ln | link file or directory |
ATTRIB | chmod | change file permissions |
CD | cd | change directory |
CHDIR | cd | change directory |
CLS | clear | clear screen |
COMP | diff, comm, cmp | file compare |
COPY | cp | file copy |
Ctl-C | Ctl-C | break (signal) |
Ctl-Z | Ctl-D | EOF (end-of-file) |
DEL | rm | delete file(s) |
DELTREE | rm -rf | delete directory recursively |
DIR | ls -l | directory listing |
ERASE | rm | delete file(s) |
EXIT | exit | exit current process |
FC | comm, cmp | file compare |
FIND | grep | find strings in files |
MD | mkdir | make directory |
MKDIR | mkdir | make directory |
MORE | more | text file paging filter |
MOVE | mv | move |
PATH | $PATH | path to executables |
REN | mv | rename (move) |
RENAME | mv | rename (move) |
RD | rmdir | remove directory |
RMDIR | rmdir | remove directory |
SORT | sort | sort file |
TIME | date | display system time |
TYPE | cat | output file to stdout |
XCOPY | cp | (extended) file copy |
Batch nok simple macam sample
@ECHO OFF
ECHO.
ECHO TOk Sample ajak. Taruh masej kitakorang kat sitok
ECHO.
PAUSE
CLS
EXIT
copy paste batch kat atas tok pasya edit kat notepad dan save as nama_file.bat, execute file ya tengok output lepasya. Pastikan file extension ya bukan *.txt
contoh seterusnya batch buang cookies dari IE.
WINNT
@ECHO OFF
ECHO ***************************************************
ECHO ** batch makei delete cookies nok sik diperlukan **
ECHO ***************************************************
del /Q c:\docume~1\alluse~1\Cookies\*.*
REM Change alluse~1 in the above line to your userID
del /q c:\winnt\temp\*.*
del /q c:\temp\*.*
del /q c:\winnt\Recent\*.*
del /q c:\*.chk
EXIT
Tambah line dibah tok pakei winXP
del /q C:\Windows\Temp\Adware\*.*
del /q C:\Windows\Temp\History\*.*
del /q C:\Windows\Temp\Tempor~1\*.*
del /q C:\Windows\Temp\Cookies\*.*
Kat dibah tok contoh molah batch file kat dalam DOS makei syntax IF, FIND, GOTO, EXITO.
VIEWDATA.BAT: DOS Batch File
REM VIEWDATA
REM INSPIRED BY AN EXAMPLE IN "DOS POWERTOOLS"
REM BY PAUL SOMERSON
@ECHO OFF
IF !%1==! GOTO VIEWDATA
REM IF NO COMMAND-LINE ARG...
FIND "%1" C:\BOZO\BOOKLIST.TXT
GOTO EXIT0
REM PRINT LINE WITH STRING MATCH, THEN EXIT.
:VIEWDATA
TYPE C:\BOZO\BOOKLIST.TXT | MORE
REM SHOW ENTIRE FILE, 1 PAGE AT A TIME.
:EXIT0
Contoh
viewdata.sh: Shell script dari bVIEWDATA.BAT
#!/bin/bash
# viewdata.sh
# Conversion of VIEWDATA.BAT to shell script.
DATAFILE=/home/bozo/datafiles/book-collection.data
ARGNO=1
# @ECHO OFF Command unnecessary here.
if [ $# -lt "$ARGNO" ] # IF !%1==! GOTO VIEWDATA
then
less $DATAFILE # TYPE C:\MYDIR\BOOKLIST.TXT | MORE
else
grep "$1" $DATAFILE # FIND "%1" C:\MYDIR\BOOKLIST.TXT
fi
exit 0 # :EXIT0
# GOTOs, labels, smoke-and-mirrors, and flimflam unnecessary.
# The converted script is short, sweet, and clean,
#+ which is more than can be said for the original.
Pakei fun stuff kitakorang leh cuba syntax macam contoh dibah tok.
Nunggah program lain
CALL C:\calc.exe
Nunggah batch file nok lain pasya berbalit ke batch nok nunggah bath ya tek.
CALL C:\WINDOWS\NEW_BATCHFILE.BAT
Looping makei GOTO
:BEGIN
REM LOOPING SIK PANDEI RENTI ....
GOTO BEGIN
Sigek agik sampel makei GOTO@ECHO OFF
:BEGIN
REM LOOPING SIK PANDEI RENTI ....
ECHO..
ECHO.. animasi fun pakei saja - saja.... bagus pakei advertisment dalam BATCH :-)
ECHO..
GOTO BEGIN
IF, IF EXIST, IF NOT EXISTIF EXIST C:\contoh.txt
DEL C:\contoh.txt
IF NOT EXIST C:\contoh.txt
COPY C:\windows\contoh.txt c:\contoh.txt
Untuk faham macam ne nukar or makei shell script atau bashing dalam *nix, buat rujukan dari internet.
0 comments:
Post a Comment