0%

linux bash tutorial

Guide

copy and zip

copy_and_zip.sh

1
2
3
4
5
6
7
8
9
10
11
12
folder_name=v1.2
folder_zip_name=$folder_name.zip
folder_path=dist/$folder_name
echo $folder_path
mkdir -p $folder_path
cp -r model static templates $folder_path
cp db.py util.py demo.py README.md CHANGELOG.md $folder_path
echo "Copying to $folder_path OK"

cd dist
zip -r $folder_zip_name $folder_name
echo "Zip to $folder_zip_name OK"

copy libs to dist

copylib.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh
# usage: ./copylib.sh ./example_opencv

bin=$1
dest="./lib"

if [ ! -d $dest ];then
echo "makedir $dest"
mkdir $dest
fi

libs=$(ldd $bin | awk '{if (match($3,"/")){ printf("%s "),$3 } }')
#echo $libs
cp $libs $dest
echo "Done"

run scripts to copy libs to lib folder.

./copylib.sh ./example_opencv

tree lib
lib
├── libc.so.6
├── libdl.so.2
├── libgcc_s.so.1
├── libjasper.so.1
├── libjbig.so.0
├── libjpeg.so.8
├── liblzma.so.5
├── libm.so.6
├── libopencv_core.so.3.1
├── libopencv_imgcodecs.so.3.1
├── libopencv_imgproc.so.3.1
├── libpng12.so.0
├── libpthread.so.0
├── librt.so.1
├── libstdc++.so.6
├── libtiff.so.5
└── libz.so.1

0 directories, 17 files

linuxdeployqt Makes Linux applications self-contained by copying in the libraries and plugins that the application uses, and optionally generates an AppImage. Can be used for Qt and other applications.

array demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash

content=$(sed -n '4p' 1.csv)
echo $content

row=`wc -l < 2.csv`
echo $row

i=0
for id in `cat 2.csv`
do
if [ $id == $content ]
then
echo $id
else
echo 'not equal'
((i=i+1))
fi
done
echo $i

# array
echo '---------------------------------------'
arr=(Hello World)
echo ${arr[0]}
echo ${arr[1]}

arr[0]="xxx"
arr[1]="yyy"
echo ${arr[0]}
echo ${arr[1]}

echo '---------------------------------------'

# array2
array=(one two three four [5]=five)

echo "Array size: ${#array[*]}"

echo "Array items:"
for item in ${array[*]}
do
printf " %s\n" $item
done

echo "Array indexes:"
for index in ${!array[*]}
do
printf " %d\n" $index
done

echo "Array items and indexes:"
for index in ${!array[*]}
do
printf "%4d: %s\n" $index ${array[$index]}
done

echo '---------------------------------------'

# array3
array=("first item" "second item" "third" "item")

echo "Number of items in original array: ${#array[*]}"
for ix in ${!array[*]}
do
printf " %s\n" "${array[$ix]}"
done
echo

# "${arr[*]}" returns all the items as a single word, whereas "${arr[@]}" returns each item as a separate word.

arr=(${array[*]})
echo "After unquoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
printf " %s\n" "${arr[$ix]}"
done
echo

arr=("${array[*]}")
echo "After * quoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
printf " %s\n" "${arr[$ix]}"
done
echo

arr=("${array[@]}")
echo "After @ quoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
printf " %s\n" "${arr[$ix]}"
done

Reference

History

  • 20190308: created.