• Linux shell get random number


    the Shell Profile:
    When a new interactive shell is started, /etc/profile, followed by /etc/bash.bashrc(if a
    bash shell), ~/.profile, and finally ~/.bashrc are executed in that order.
    PATH
    You can set your PATHenvironment variable to tell the shell where to search for programs (and scripts)
    to be run. The main system commands are in /bin, /usr/bin, /sbin, and /usr/sbin, but you may
    have your own scripts in $HOME/bin, $HOME/scripts, /usr/local/bin, or elsewhere. Append these to
    the PATHso that they will be found by the shell even when you are not in that directory:
    PATH=${PATH}:${HOME}/bin
    ls aliases
    Because it is such a common command, there are a few popular lsaliases, the two most common
    being llfor ls -land lafor ls -a. Your distribution might even set these for you. Some popular
    lsaliases include:
    # save fingers!
    alias l=’ls’
    # long listing of ls
    alias ll=’ls -l’
    # colors and file types
    alias lf=’ls -CF’
    # sort by filename extension
    alias lx=’ls -lXB’
    # sort by size
    alias lk=’ls -lSr’
    # show hidden files
    alias la=’ls -A’
    # sort by date
    alias lt=’ls -ltr’

    History:
    # append, don’t overwrite the history
    shopt -s histappend
    # control the size of the history file
    export HISTSIZE=100000
    export HISTFILESIZE=409600
    # ignore common commands
    export HISTIGNORE=”:pwd:id:uptime:resize:ls:clear:history:”
    # ignore duplicate entries
    export HISTCONTROL=ignoredups
    history

    ~/.inputrc and /etc/inputrc
    /etc/inputrcand ~/.inputrcare used by GNU readline facility (used by bash and many other
    utilities to read a line of text from the terminal) to control how readline behaves.
    set completion-ignore-case On

    http_proxy = serveraddress
    proxy_user = username
    proxy_password = password

    sample:
    echo "My name is  basename $0  - I was called as $0"
    echo "I was called with $# parameters."
    count=1
    while [ "$#" -ge "1" ]; do
    echo "Parameter number $count is: $1"
    let count=$count+1
    shift
    done

    $ ./manyparams.sh one two three
    My name is manyparams.sh - I was called as ./manyparams.sh
    I was called with 3 parameters.
    Parameter number 1 is: one
    Parameter number 2 is: two
    Parameter number 3 is: three

    生成序列的方法:
    seq 10 -1 1
    seq 1 1 10
    seq last
    seq first incr last
    seq first last
    生成随机数的方法:
    $RANDOM
    RANDOM produces a random number between 0 and 32767.
    if you want to generate data between m...n , write a function
    function getrand()
    {
    MIN=$1
    MAX=$2
    let "RANGE=$MAX-$MIN";
    if [ "$RANGE" -le "0" ]; then
    echo "Error - MAX IS LESS THAN MIN"
    fi
    #(())表示数学运算
    return $(($RANDOM % $RANGE +$MIN))
    }
    getrand 1 1000
    #$?表示返回值
    echo $?

    if 判断中常用的一些表达式:
    -d :判断制定的是否为目录
    -z:判断制定的变量是否存在值
    -f:判断制定的是否为文件
    -L:判断制定的是否为符号链接
    -r:判断制定的是否可读
    -s:判断存在的对象长度是否为0
    -w:判断制定的是否可写
    -x:判断存在的对象是否可以执行
    !:测试条件的否定符号

    time format
     echo $(date "+%Y%m%d %H:%M:%S")

    IFS
    IFS is the Internal Field Separator: It lists the set of characters that may be used as whitespace. Its
    default value is <space><tab><newline>
    IFS=$(echo )

    Looking for a job working at Home about MSBI
  • 相关阅读:
    BZOJ4896 THUSC2016补退选(trie)
    BZOJ4892 Tjoi2017dna(后缀数组)
    BZOJ4890 Tjoi2017城市
    BZOJ4888 Tjoi2017异或和(树状数组)
    BZOJ4887 Tjoi2017可乐(动态规划+矩阵快速幂)
    BZOJ4883 棋盘上的守卫(环套树+最小生成树)
    BZOJ4881 线段游戏(二分图+树状数组/动态规划+线段树)
    BZOJ4878 挑战NP-Hard(dfs树)
    BZOJ5466 NOIP2018保卫王国(倍增+树形dp)
    BZOJ4873 Shoi2017寿司餐厅(最小割)
  • 原文地址:https://www.cnblogs.com/huaxiaoyao/p/4438114.html
Copyright © 2020-2023  润新知