Created
August 16, 2011 12:05
-
-
Save tyuki39/1148930 to your computer and use it in GitHub Desktop.
バッチファイルとシェルスクリプトの雑多な例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SET VARIABLE1=VALUE1 | |
IF NOT DEFINED VARIABLE1 ( | |
SET VARIABLE1=DEFAULT1 | |
) | |
IF NOT DEFINED VARIABLE2 ( | |
SET VARIABLE2=DEFAULT2 | |
) | |
echo %VARIABLE1% | |
echo %VARIABLE2% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export VARIABLE1=VALUE1 | |
export ${VARIABLE1=DEFAULT1} | |
export ${VARIABLE2=DEFAULT2} | |
echo $VARIABLE1 | |
echo $VARIABLE2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SET COUNT=1 | |
SET /A COUNT=%COUNT%+1 | |
echo %COUNT% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COUNT=1 | |
COUNT=`expr $COUNT + 1` | |
echo $COUNT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
echo BEGIN | |
echo. | |
echo END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo BEGIN | |
echo | |
echo END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
CALL :SETENV VARIABLE "date /t" | |
@ECHO %VARIABLE% | |
EXIT /B 0 | |
:SETENV | |
SET %1= | |
FOR /F "USEBACKQ TOKENS=*" %%r IN (`%2`) DO ( | |
SET %1=%%r | |
EXIT /B 0 | |
) | |
EXIT /B 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VARIABLE=`date +%Y/%m/%d` | |
echo $VARIABLE | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
FOR /L %%i IN (1,1,100) DO ( | |
SET NUM_WITH_PAD=000%%i | |
SET NUM_WITH_PAD=!NUM_WITH_PAD:~-3! | |
echo !NUM_WITH_PAD! | |
) | |
ENDLOCAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment