mirror of
https://github.com/eddyem/lectures.git
synced 2026-03-21 17:20:57 +03:00
add 3 lectures for SFedU
This commit is contained in:
10
Komp_obr_SFedU/Materials4Pract/01/a.c
Executable file
10
Komp_obr_SFedU/Materials4Pract/01/a.c
Executable file
@@ -0,0 +1,10 @@
|
||||
//usr/bin/gcc $0 && exec ./a.out "$@"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
for(int x = 1; x < argc; ++x)
|
||||
printf("arg %d is %s\n", x, argv[x]);
|
||||
printf("Done\n");
|
||||
return 0;
|
||||
}
|
||||
12
Komp_obr_SFedU/Materials4Pract/01/args
Executable file
12
Komp_obr_SFedU/Materials4Pract/01/args
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
function chkargs(){
|
||||
echo "you give $# arguments:"
|
||||
for arg in "$@"; do
|
||||
echo -e "\t$arg"
|
||||
done
|
||||
}
|
||||
|
||||
chkargs "$@"
|
||||
chkargs "$*"
|
||||
chkargs $*
|
||||
6
Komp_obr_SFedU/Materials4Pract/01/array
Executable file
6
Komp_obr_SFedU/Materials4Pract/01/array
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
array=(1 2 3 4 [5]=next [10]=last)
|
||||
echo "array with size ${#array[*]} and indexes ${!array[*]}: ${array[*]}"
|
||||
echo "array[4]=${array[4]}, array[10] len=${#array[10]}"
|
||||
|
||||
15
Komp_obr_SFedU/Materials4Pract/01/awkscript1
Normal file
15
Komp_obr_SFedU/Materials4Pract/01/awkscript1
Normal file
@@ -0,0 +1,15 @@
|
||||
BEGIN {
|
||||
print "List of users and shells"
|
||||
print " UserName \t HomePath"
|
||||
print "-----------------------"
|
||||
FS=":"
|
||||
}
|
||||
{
|
||||
print $1 " \t " $6
|
||||
}
|
||||
END {
|
||||
home=ENVIRON["HOME"]
|
||||
name=ENVIRON["USER"]
|
||||
print "-----------------------"
|
||||
print "Your name is " name " and home is " home
|
||||
}
|
||||
11
Komp_obr_SFedU/Materials4Pract/01/awkscript2
Normal file
11
Komp_obr_SFedU/Materials4Pract/01/awkscript2
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
if ($1 > 20)
|
||||
{
|
||||
x = $1 * 2
|
||||
print x
|
||||
} else
|
||||
{
|
||||
x = $1 / 2
|
||||
print x
|
||||
}
|
||||
}
|
||||
11
Komp_obr_SFedU/Materials4Pract/01/case
Executable file
11
Komp_obr_SFedU/Materials4Pract/01/case
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
while [ -n "$1" ];do
|
||||
case "$1" in
|
||||
-a) echo "Found the -a option" ;;
|
||||
-b) echo "Found the -b option" ;;
|
||||
-c) echo "Found the -c option" ;;
|
||||
*) echo "$1 is not an option" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
7
Komp_obr_SFedU/Materials4Pract/01/ex1
Executable file
7
Komp_obr_SFedU/Materials4Pract/01/ex1
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: $0 LEN - get random number with length LEN"
|
||||
exit 1
|
||||
fi
|
||||
cat /dev/urandom | tr -dc '0-9' | fold -w $1 | head -n 1
|
||||
10
Komp_obr_SFedU/Materials4Pract/01/ex2
Executable file
10
Komp_obr_SFedU/Materials4Pract/01/ex2
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
for ((nl = 1; nl < 1001; ++nl)); do
|
||||
one=$((RANDOM % 1001))
|
||||
two=$((RANDOM % 41 - 20))
|
||||
#three=$(echo "scale=3; $((SRANDOM % 100001)) / 1000" | bc -l)
|
||||
R=$((SRANDOM % 100001))
|
||||
three=$(echo "$R" | awk '{printf "%.3f", $1/1000}')
|
||||
echo -e "$nl\t$one\t$two\t$three"
|
||||
done
|
||||
8
Komp_obr_SFedU/Materials4Pract/01/ex3
Executable file
8
Komp_obr_SFedU/Materials4Pract/01/ex3
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
OUT=1000strings
|
||||
|
||||
./ex2 1000 > $OUT
|
||||
for ((i = 2; i < 5; ++i)); do
|
||||
sort -n -k $i $OUT > ${OUT}_$i
|
||||
done
|
||||
|
||||
22
Komp_obr_SFedU/Materials4Pract/01/ex4
Executable file
22
Komp_obr_SFedU/Materials4Pract/01/ex4
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -ne 1 ]; then echo "Usage: $0 word"; exit 1; fi
|
||||
|
||||
TOTAL=0
|
||||
miss=0; hit=0;
|
||||
|
||||
while true; do
|
||||
TOTAL=$((TOTAL+1))
|
||||
ans=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 100 | head -n1 | grep $1)
|
||||
if [ -x$ans = -x ]; then
|
||||
miss=$((miss+1))
|
||||
else
|
||||
echo "$ans"
|
||||
hit=$((hit+1))
|
||||
fi
|
||||
[ $hit -ge 5 -o $TOTAL -ge 10000 ] && break
|
||||
done
|
||||
|
||||
part=$(echo "$hit $TOTAL" | awk '{ printf "%.2f", $1*100/$2}')
|
||||
|
||||
echo "Miss: $miss, Hit: $hit (${part}%)"
|
||||
19
Komp_obr_SFedU/Materials4Pract/01/for
Executable file
19
Komp_obr_SFedU/Materials4Pract/01/for
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo -e "\t1."
|
||||
|
||||
for (( a = 1; a < 11; ++a )); do
|
||||
echo "a=$a"
|
||||
done
|
||||
|
||||
echo -e "\n\t2."
|
||||
|
||||
for a in $(seq 1 10); do
|
||||
echo "a=$a"
|
||||
done
|
||||
|
||||
echo -e "\n\t3."
|
||||
|
||||
for a in one "two args" three; do
|
||||
echo "a=$a"
|
||||
done
|
||||
15
Komp_obr_SFedU/Materials4Pract/01/if
Executable file
15
Komp_obr_SFedU/Materials4Pract/01/if
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Enter value"
|
||||
read val
|
||||
if [ $val -gt 100 ]; then
|
||||
echo "value $val greater than 100";
|
||||
else
|
||||
echo "value $val less than 100";
|
||||
fi
|
||||
|
||||
echo "Enter filename"
|
||||
read f
|
||||
[ -d $f ] && echo "$f is a directory"
|
||||
[ -f $f ] && echo "$f is a file"
|
||||
[ ! -e $f ] && echo "Not exists"
|
||||
43
Komp_obr_SFedU/Materials4Pract/01/takeexp
Executable file
43
Komp_obr_SFedU/Materials4Pract/01/takeexp
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
# array with filter positions (0 - hole, 1 - B, 2 - V, 3 - R, 4 - r')
|
||||
POSITIONS=( 1 2 3 )
|
||||
# array with expositions (in milliseconds!!!) for each position from POSITIONS
|
||||
EXPTIME=( 600000 300000 400000 )
|
||||
# array with focus (mm*10000) for each position
|
||||
FOCUS=( 45000 45500 45300 )
|
||||
|
||||
# array size
|
||||
len=${#POSITIONS[*]}
|
||||
|
||||
__x=0
|
||||
function chkweather(){
|
||||
local y=$__x
|
||||
__x=$((__x+1))
|
||||
return $y
|
||||
}
|
||||
|
||||
function move_focuser(){
|
||||
echo "move focuser to $1"
|
||||
}
|
||||
|
||||
function move_turret(){
|
||||
echo "move turret to $1"
|
||||
}
|
||||
|
||||
function capture_frame(){
|
||||
echo "capture frame with exposition $1 to file prefix $2"
|
||||
}
|
||||
|
||||
function take_image(){
|
||||
for (( i=0; i<$len; i++ )); do
|
||||
move_focuser ${FOCUS[i]}
|
||||
move_turret ${POSITIONS[i]}
|
||||
capture_frame ${EXPTIME[i]} filename
|
||||
done
|
||||
}
|
||||
|
||||
while chkweather; do
|
||||
take_image
|
||||
done
|
||||
|
||||
echo "stop_observations"
|
||||
7
Komp_obr_SFedU/Materials4Pract/01/while
Executable file
7
Komp_obr_SFedU/Materials4Pract/01/while
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
while read X; do
|
||||
echo "You entered: $X"
|
||||
done
|
||||
|
||||
echo "End"
|
||||
Reference in New Issue
Block a user