邓心一 7 éve
szülő
commit
6b75de257d
4 módosított fájl, 67 hozzáadás és 0 törlés
  1. 2 0
      2/crontab.sh
  2. 23 0
      3/simple.sh
  3. 41 0
      4/suits.sh
  4. 1 0
      5/file.sh

+ 2 - 0
2/crontab.sh

@@ -1,3 +1,5 @@
 crontab -e
 
+20 2 * * * rm -rf /confbackup/*
 
+0 8-14 * * * cat /home/user/workspace/*.log >> /backup/bak.txt

+ 23 - 0
3/simple.sh

@@ -0,0 +1,23 @@
+# simple shell script
+
+#!/bin/bash
+groupadd students
+for i in {1..20}
+do
+  useradd stu$i
+  if [ $? -eq 0 ];then
+    echo -e "add user stu$i\n"
+  else
+    echo -e "add user stu$1 failed\n"
+  fi
+done
+
+#!/bin/bash
+printf "Decimal\tHex\tCharactor\n"
+printf "-------------------------\n"
+for i in {33..126}
+do
+  printf "%d\t%x\t" $i $i
+  printf \\$(printf "%03o" $i)
+  printf "\n"
+done

+ 41 - 0
4/suits.sh

@@ -0,0 +1,41 @@
+#!/bin/bash
+
+declare -a color=("spade" "heart" "club" "diamond")
+declare -a point=("A" "2" "3" "4" "5" "6" "7" "8" "9" "10" "J" "Q" "K")
+
+function seed_random() {
+  local min=$1
+  local max=$2
+  seq $1 $2 | shuf -n $(($2-$1+1))
+}
+
+function deal_cards() {
+  local cards=$1
+  local beg=$2
+  local end=$3
+  local cnt=0
+  for i in $cards
+  do
+    if [ $cnt -eq $end ];then
+      return
+    fi
+    if [ $cnt -ge $beg ];then
+      printf ${color[$(($i%4))]}${point[$(($i%13))]}" "
+    fi
+    cnt=$(($cnt+1))
+  done
+}
+
+function main() {
+  card_idx=$(seed_random 0 51)
+  printf "first one: "
+  deal_cards "$card_idx" 0 13
+  printf "\nsecond one: "
+  deal_cards "$card_idx" 13 26
+  printf "\nthird one: "
+  deal_cards "$card_idx" 26 39
+  printf "\nfourth one: "
+  deal_cards "$card_idx" 39 52
+}
+
+main

+ 1 - 0
5/file.sh

@@ -0,0 +1 @@
+# (1)