2023年1月10日星期二

C# TaskRun with parameter and return

====================
private bool IsSkipInput(string content)
{
    if (skipInput == null) return false;

    // skip if match the pattern
    if (skipInput.isTrue(content)) return true;
    return false;
}
====================
public async void matchText(string content, List<Match> matches)
{
    if (string.IsNullOrEmpty(pattern)) return;
    
    bool isSkipOK = await Task.Run<bool>(() => { return IsSkipInput(content); });
    if (isSkipOK)
    {
        return ;
    }
}

2022年12月7日星期三

shell different between return and exit

1. return used in function, 
    shell will continue after return from function 

2. exit used in everywhere of shell, stop and exit shell immediately.

example:
#========================
function testreturn(){
   echo "It will return 1"
   return 1
}

function testexit(){
   echo "It will exit 1"
   exit 1 
}

echo "start..."
testreturn
echo " after return "
testexit
echo " after exit"
#========================
#run result:
start...
It will return 1
after return 
It will exit 1
==========================

2022年11月17日星期四

check file changed or not by md5 hash code

windows powershell command:

PS C:\Users\test> certutil -hashfile destfile.zip md5

MD5 hash (対象 destfile.zip):

f6cb78afe66b417cd3f79df8d1c86444 

CertUtil: -hashfile コマンドは正常に完了しました。

linux command:

md5sum destfile.zip

 f6cb78afe66b417cd3f79df8d1c86444 destfile.zip


2022年11月11日星期五

git clone -b branchname url

git clone -b branchname https://domainname/group/project.git 


git clone -b branchname https://userid:token@domainname/group/project.git 


2022年11月8日星期二

Linux refresh .bashrc immediately source ~/.bashrc

 source ~/.bashrc 

linux shell setfacl /getfacl

$ setfacl --help

setfacl 2.2.51 -- set file access control lists Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ... -m, --modify=acl modify the current ACL(s) of file(s) -M, --modify-file=file read ACL entries to modify from file -x, --remove=acl remove entries from the ACL(s) of file(s) -X, --remove-file=file read ACL entries to remove from file -b, --remove-all remove all extended ACL entries -k, --remove-default remove the default ACL --set=acl set the ACL of file(s), replacing the current ACL --set-file=file read ACL entries to set from file --mask do recalculate the effective rights mask -n, --no-mask don't recalculate the effective rights mask -d, --default operations apply to the default ACL -R, --recursive recurse into subdirectories -L, --logical logical walk, follow symbolic links -P, --physical physical walk, do not follow symbolic links --restore=file restore ACLs (inverse of `getfacl -R') --test test mode (ACLs are not modified) -v, --version print version and exit -h, --help this help text

#ex: $ setfacl -m u:testuser :rw test1.log
setfacl: Option -m incomplete
$ setfacl -m u:testuser:rw test1.log
$ getfacl test1.log
# file: test1.log # owner: ec2-user # group: ec2-user user::rw- user:ec2-user:rwx group::rw- mask::rwx other::r--

2022年11月1日星期二

shell if and or

 

  • && (AND) : if [ condition1 ] && [ condition2 ]; then 
       if [ -f $src/* ] && [ -d $dest ]; then 

          echo "there are files under $src"
          cp -rf $src/* $dest/
       else
          echo " directory $
dest is not found, or no files under $src" 
       fi


  • || (OR) : if [ condition1 ] || [ condition2 ]; then