wys的个人博客

你有很多事放不下?做人要潇洒一点~

0%

Shell Tools and Scripting课后练习

Shell Tools and Scripting课后练习

  1. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    rust@DESKTOP-L4PLVQ4:~/missing$ ls -lhat --color
    total 0
    -rw-r--r-- 1 rust rust 7 Mar 27 16:18 foo1
    drwxr-xr-x 1 rust rust 4.0K Mar 26 22:01 ..
    drwxr-xr-x 1 rust rust 4.0K Mar 26 18:55 .
    -rwxrwxrwx 1 rust rust 83 Mar 26 18:55 script.py
    drwxr-xr-x 1 rust rust 4.0K Mar 26 18:19 bar
    drwxr-xr-x 1 rust rust 4.0K Mar 26 18:19 foo
    -rw-r--r-- 1 rust rust 0 Mar 26 18:11 foo10
    -rw-r--r-- 1 rust rust 0 Mar 26 18:11 foo2
    drwxr-xr-x 1 rust rust 4.0K Mar 26 17:14 b
  1. 1
    2
    3
    4
    5
    6
    7
    8
    #marco.sh
    #!/bin/bash
    marco() {
    export MARCO=$(pwd)
    }
    polo() {
    cd "$MARCO"
    }
1
2
3
4
5
6
rust@DESKTOP-L4PLVQ4:~/missing/test$ source marco.sh
rust@DESKTOP-L4PLVQ4:~/missing/test$ cd ..
rust@DESKTOP-L4PLVQ4:~/missing$ marco
rust@DESKTOP-L4PLVQ4:~/missing$ cd
rust@DESKTOP-L4PLVQ4:~$ polo
rust@DESKTOP-L4PLVQ4:~/missing$
  1. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    count=1

    while true
    do
    ./buggy.sh 2> out.log
    if [[ $? -ne 0 ]]; then
    echo "failed after $count times"
    cat out.log
    break
    fi
    ((count++))

    done