Created
September 6, 2011 11:09
-
-
Save tyuki39/1197286 to your computer and use it in GitHub Desktop.
バッチファイルとシェルスクリプトの雑多な例2
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 CURRENTDIR=%CD% | |
echo %CURRENTDIR% |
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
CURRENTDIR=$PWD | |
echo $CURRENTDIR |
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 yyyymmdd=%DATE:/=% | |
echo %yyyymmdd% | |
SET HHMMSS=%TIME::=% | |
SET HHMMSS=%HHMMSS:~0,-3% | |
SET HHMMSS=%HHMMSS: =0% | |
echo %HHMMSS% | |
SET ymdHMS=%yyyymmdd%%HHMMSS% | |
echo %ymdHMS% | |
FOR /F "tokens=1-6 delims=/:." %%a IN | |
("%DATE%:%TIME%: =0%") DO ( | |
SET ymdHMS=%%a%%b%%c%%d%%e%%f | |
) | |
echo %ymdHMS% |
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
yyyymmdd=`date +%Y%m%d` | |
echo $yyyymmdd | |
HHMMSS=`date +%H%M%S` | |
echo $HHMMSS | |
ymdHMS=`date +%Y%m%d%H%M%S` | |
echo $ymdHMS | |
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 | |
dir *.nonexistent | |
IF %ERRORLEVEL% NEQ 0 ( | |
echo ERROR | |
) |
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
ls *.nonexistent | |
if [ $? -ne 0 ]; then | |
echo ERROR | |
fi |
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 | |
dir *.nonexistent | |
echo %ERRORLEVEL% | |
echo %ERRORLEVEL% | |
date /t > nul | |
echo %ERRORLEVEL% |
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
ls *.nonexistent | |
echo $? | |
echo $? | |
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 | |
dir *.existent && EXIT /B 0 | |
dir *.nonexistent || 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
ls *.existent && exit 0 | |
ls *.nonexistent || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment