linux 和windows批量按日期組建檔案名

來源:互聯網
上載者:User

Windows BAT批次檔

 代碼如下 複製代碼

@echo off
set time_hh=%time:~0,2%
if /i %time_hh% LSS 10 (set time_hh=0%time:~1,1%)
set filename=%date:~,4%%date:~5,2%%date:~8,2%_%time_hh%%time:~3,2%%time:~6,2%
echo test >> %filename%.txt

linux shell

 

 代碼如下 複製代碼
#!/bin/sh
echo test >> $(date -d "today" +"%Y%m%d_%H%M%S").txt

提供一些關於linux shell的命令參考。

要實現的功能
C語言編程
Linux Shell指令碼編程
程式/指令碼的參數傳遞
int main(int argc, char** argv)
{
if (argv != 4) {
    printf( “Usage: %s arg1 arg2 arg3”, argv[0] );
    return 1;
}
 
printf(“arg1:%s/n”,argv[1]);
printf(“arg2:%s/n”,argv[2]);
printf(“arg3:%s/n”,argv[3]);
return 0;
}
#!/bin/sh
 
if [ $# -lt 3 ]; then
    echo "Usage: `basename $0` arg1 arg2 arg3" >&2
    exit 1
fi
 
echo "arg1: $1"
echo "arg2: $2"
echo "arg3: $3"
exit 0
int main(int argc, char** argv)
{
    int i;
for (i=1; i<=argc;i++) {
printf(“arg:%s/n”,argv[i]);
}
return 0;
}
#!/bin/sh
 
while [ $# -ne 0 ]
do
    echo "arg: $1"
    shift
done
邏輯/數值運算
if (d == 0)
if [ "$D" -eq "0" ] ; then
if (d != 0)
if [ "$D" -ne "0" ] ; then
if (d > 0)
if [ "$D" -gt "0" ] ; then
if (d < 0)
if [ "$D" -lt "0" ] ; then
if (d <= 0)
if [ "$D" -le "0" ] ; then
if (d >= 0)
if [ "$D" -ge "0" ] ; then
字串比較
if (strcmp(str,”abc”)==0) {
}
if [ "$STR" != "abc" ]; then
fi
輸入和輸出
scanf(“%d”,&D);
read D
printf( “%d”, D);
echo –n $D
printf( “%d”,D);
echo $D
printf( “Press any to continue...”);
char ch=getchar();
printf( “/nyou pressed: %c/n”, ch );
#!/bin/sh
 
getchar()
{
SAVEDTTY=`stty -g`
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -cbreak
stty $SAVEDTTY
}
 
echo -n "Press any key to continue..."
CH=`getchar`
echo ""
echo "you pressed: $CH"
 
read D <&3
程式/指令碼的控制流程程
if (isOK) {
    //1
} else if (isOK2) {
    //2
} else {
    //3
}
if [ isOK ]; then
    #1
elif [ isOK2 ]; then
    #2
else
    #3
fi
switch (d)
{
case 1:
printf(“you select 1/n”);
break;
case 2:
case 3:
printf(“you select 2 or 3/n”);
break;
default:
printf(“error/n”);
break;
};
case $D in
1) echo "you select 1"
    ;;
2|3) echo "you select 2 or 3"
    ;;
*) echo "error"
    ;;
esac
for (int loop=1; loop<=5;loop++) {
     printf( “%d”, loop);
}
for loop in 1 2 3 4 5
do
    echo $loop
done
do {
    sleep(5);
} while( !isRoot );
IS_ROOT=`who | grep root`
until [ "$IS_ROOT" ]
do
    sleep 5
done
counter=0;
while( counter < 5 ) {
printf( “%d/n”, counter);
counter++;
}
COUNTER=0
while [ $COUNTER -lt 5 ]
do
echo $COUNTER
    COUNTER=`expr $COUNTER + 1`
done
while (1) {
}
while :
do
done
break;
break或break n,n表示跳出n級迴圈
continue;
continue
函數與過程的定義
void hello()
{
    printf( “hello/n” );
}
…
//函數調用
hello();
hello()
{
    Echo “hello”
} 或者
function hello()
{
    Echo “hello”
}
…
#函數調用
hello
函數的參數和傳回值
int ret = doIt();
if (ret == 0) {
    printf( “OK/n” );
}
doIt
if [ “$?” –eq 0 ] ; then
echo “OK”
fi
或者
RET = doIt
if [ “$RET” –eq “0” ] ; then
echo “OK”
fi
int sum(int a,int b)
{
return a+b;
}
int s = sum(1,2);
printf(“the sum is: %d/n”, s);
sum()
{
    echo -n "`expr $1 + $2`"
}
S=`sum 1 2`
echo "the sum is: $S"
bool isOK() { return false; }
if (isOK) {
    printf( “YES/n” );
} else {
    printf( “NO/n” );
}
isOK()
{
    return 1;
}
if isOK ; then
    echo "YES"
else
    echo "NO"
fi

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.