Linux and Windows batch name generation by date

Source: Internet
Author: User
Tags sleep

Windows bat Batch File

The code is as follows Copy Code

@echo off
Set time_hh=%time:~0,2%
if/i%time_hh% LSS (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

The code is as follows Copy Code
#!/bin/sh
echo Test >> $ (date-d "Today" + "%y%m%d_%h%m%s"). txt

Provides some command references about the Linux shell.

The functionality to implement
C Language Programming
Linux Shell Script Programming
Parameter passing of program/script
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 [$#- Span>lt 3]; Then
    echo Usage: ' basename $ ' arg1 arg2 arg3 ' >&2
    exit 1
fi
 
echo "Arg1: $"
echo "arg2: $"
echo "Arg3: $"
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
& nbsp;   echo "ARG: $"
    shift
do Ne
Logical/numeric operations
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
String comparisons
if ( strcmp (str, "abc") ==0) {
}
If ["$STR"!= " abc"]; then
Fi
Input and output
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
program/script Control process
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 ("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
Todo
Echo $loop
Done
do {
Sleep (5);
while (! isRoot);
Is_root= ' who | grep Root '
Until ["$IS _root"]
Todo
Sleep 5
Done
counter=0;
while (Counter < 5) {
printf ("%d/n", counter);
counter++;
}
Counter=0
While [$COUNTER- LT 5]
Todo
Echo $COUNTER
Counter= ' expr $COUNTER + 1 '
Done
while (1) {
}
While:
Todo
Done
Break
Break or break n,n means jump out of n-level loops
Continue
Continue
Definitions of functions and procedures
void Hello ()
{
printf ("hello/n");
}
...
Function call
Hello ();
Hello ()
{
Echo "Hello"
} or
function Hello ()
{
Echo "Hello"
}
...
#函数调用
Hello
function parameters and return values
int ret = doIt ();
if (ret = 0) {
    printf ("ok/n");
}
doIt
if [$?] – eq 0]; then
echo "OK"
fi
or
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 ()
{
 &nb sp;  echo-n "Expr $ + $"
}
s= ' sum 1 2 '
Ech O "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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.