LEARN

for i in {0..65535} ; do printf "%x\n" $i ; done \
| while read -r hex ; do printf "$hex(%d): \U$hex\n" 0x$hex ; done

arrays

end_date=($(date --date "$(date +%Y-%m-01) -1 day" "+%d %m %y"))
start_date=(${end_date[*]})
start_date[0]="01"

echo ${start_date} # 01
echo "${#start_date}" # 2
echo ${start_date[*]} # 01 04 20
echo "${#start_date[*]}" # 3

echo ${end_date[*]} # 30 04 20
echo "${start_date[@]:0:2}" # 01 04

@TaG: ArraY

bug ?

$SHELL --version && export LANG=C ; for i in $(seq 1 20) ; do  printf "[%d]\n" 0$i ; done 2>&1 | grep ": invalid"
GNU bash, version 3.2.48(1)-release (i486-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
bash: printf: 08: invalid number
bash: printf: 09: invalid number
bash: printf: 018: invalid number
bash: printf: 019: invalid number

$SHELL --version && export LANG=C ; for i in $(seq 1 20) ; do  printf "[%d]\n" 0$i ; done 2>&1 | grep ": invalid"
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
bash: printf: 08: invalid octal number
bash: printf: 09: invalid octal number
bash: printf: 018: invalid octal number
bash: printf: 019: invalid octal number

Fixed in :

GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)

GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)

bash: printf: 08: invalid octal number
bash: printf: 09: invalid octal number
printf "[%04d]\n" 9              
[0009]

@TaG: PrintF

fork bomb

:(){:|:&};: # fork bomb 
url=http://view.atdmt.com/action/dlXP ; while [ true ] ;do wget -O /dev/null $url ; sleep 1 ; done

${#foo}

display_string_by_packet()
{
    res_string=""
    packet_len=1
    [ "_" != "_${2}" ] && packet_len=$2
    if [ 0 -lt ${packet_len} ] ; then
        src_string=${1}
        pos=${#src_string}
        len=${packet_len}
        while [ 0 -lt ${pos} ] ; do
            pos=$((pos-${packet_len}))
            if [ 0 -ge ${pos} ] ; then
                len=$((${packet_len}+${pos}))
                pos=0
            fi
            res_string=${src_string:${pos}:${len}}" "${res_string}
        done
    fi
    echo -n ${res_string}
}


display_string_by_packet "this is a test" 2
#| th is i s a te st

$@

echo $@ | sort | while read t ; do cat "$t" ; done > "${file}"

getopts

env

# rzr@lap:tmp/ # [126] # mkdir  /tmp/bin/; touch /tmp/bin/script.sh
# rzr@lap:tmp/ # [0] #  PATH="/tmp/bin:$PATH" which script.sh
# rzr@lap:tmp/ # [1] #  PATH="/tmp/bin:$PATH" script.sh
bash: /tmp/bin/script.sh: Permission denied

MISC

MORE

bash.txt · Last modified: 2020/09/15 17:22 by rzr
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki