Ubuntu 管理心得

搜尋此網誌

顯示具有 bash scripts 標籤的文章。 顯示所有文章
顯示具有 bash scripts 標籤的文章。 顯示所有文章

2024年9月9日 星期一

for loop

#!/bin/bash

for i in {1..5}
do
   echo "Welcome $i times"
done

2024年9月5日 星期四

block comments

#!/bin/bash
echo "Something"
: <<
MyComments
akldsj 
aklsdfj kald'fa
kaldjsf adsf
MyComments

2024年3月23日 星期六

mkLectNote_clean_tex.sh

#!/bin/bash
TeXfile=$1
LyXfile="${1%.*}.lyx"

sed -i -e '0,/\\maketitle$/d' -e '/^\\end{document}/d' -e '/hypertarget/d' -e 's/\\label.*$//' -e 's/\\section/\\chapter/g' -e 's/\\subsection/\\section/g' -e 's/\\subsubsection/\\subsection/g'  -e 's/\\textgreater/>/'  $TeXfile
sed -i '1 i\\\\def\\mylabel#1{\\label{#1}}' $TeXfile

#sed -i 's/\/\\/g' $TeXfile


2024年3月8日 星期五

slide show jpeg files, feh

#!/bin/bash
if [ "$#" -lt 2 ]; then
    echo "Usage: $0 <delay sec.> <subdirerory>"
    exit
fi
feh -r -d -Z -D ${1} #{2}


                     

2024年2月23日 星期五

sync onedrive

#!/bin/bash
if [ "$#" -lt 1 ]; then
#    echo "Usage: $0 <upload_path>"
    echo "Usage: $0 <full local  directory> "
    echo "e.g. $0 /home/chiao/Python"
    exit
fi
SUBDIR=$(basename "$1")
ROOTPATH=$(dirname "$1")
read -p "Start dryrun (press y or n) ? " yn
case $yn in
#     [Yy]* ) echo "Start dryrun (not really uploading) ..." ;onedrive --synchronize --verbose --resync --dry-run;;
#     [Yy]* ) echo "Start dryrun (not really uploading) ..." ;onedrive --syncdir ${1} --synchronize --skip-symlinks  --verbose --dry-run --resync;;
     [Yy]* ) echo "Start dryrun (not really uploading) ..." ;onedrive --syncdir ${ROOTPATH} --single-directory ${SUBDIR} --synchronize --skip-symlinks  --verbose --dry-run --resync;;
#     [Yy]* ) echo "Start dryrun (not really uploading) ..." ;echo "Testing dryrun";;
esac     
read -p "Strat uploading? (press y or n) " yn
case $yn in
#    [Yy]* ) echo "-----------------------------------------------------------";START=$(date +%F\ %T);onedrive --synchronize --verbose --resync; echo "Start at:  $START"; echo "End at: $(date +%F\ %T)"; echo "-----------------------------------------------------------";;
#    [Yy]* ) echo "-----------------------------------------------------------";START=$(date +%F\ %T);onedrive --syncdir ${1} --synchronize --skip-symlinks --verbose --resync; echo "Start at:  $START"; echo "End at: $(date +%F\ %T)"; echo "-----------------------------------------------------------";;
    [Yy]* ) echo "-----------------------------------------------------------";START=$(date +%F\ %T);onedrive --syncdir ${ROOTPATH} --single-directory ${SUBDIR} --synchronize --skip-symlinks --verbose --resync; echo "Start at:  $START"; echo "End at: $(date +%F\ %T)"; echo "-----------------------------------------------------------";;
#     [Yy]* ) echo "-----------------------------------------------------------";START=$(date +%F\ %T); echo "Testing";echo "Start at:  $START"; echo "End at: $(date +%F\ %T)"; echo "-----------------------------------------------------------";;
    [Nn]* ) exit;;
    * ) echo "Please answer yes or no.";;
esac

2024年1月27日 星期六

bash check number of input arguments

#!/bin/bash
if [ "$#" -lt 1 ]; then
    echo "Usage: $0 <arg1>"
    exit
fi

2024年1月19日 星期五

Engineering Graphics Lecture Notes, mkEngGraLectureNotes.sh

#!/bin/bash
docxfile=$1
TeXfile=$2
LyXfile="${2%.*}.lyx"
pandoc --extract-media ./ $docxfile -o $TeXfile
sed -i -e '/hypertarget/d' -e 's/\\label.*$//' -e 's/includegraphics\[width=.*\]/includegraphics/' -e '/includegraphics{/i \\\\begin\{figure\}\n\\begin\{centering\}' -e '/includegraphics{/a \\\end\{centering\}\n\\caption\{\}\n \\\end\{figure\}' -e 's/\\textgreater/>/' $TeXfile
#sed -i 's/\/\\/g' $TeXfile
echo " \\end{document}" >> $TeXfile

cat > tmpfile << EOF
\\documentclass[10pt,a4paper]{extarticle}
\\usepackage[utf8]{inputenc}
\\usepackage{amsmath}
\\usepackage{amsthm}
\\usepackage{fontspec}
\\setmainfont[Mapping=tex-text]{Noto Serif CJK TC}
\\setsansfont[Mapping=tex-text]{Noto Serif CJK TC}
\\setmonofont{Noto Serif CJK TC}
\\usepackage{float}
\\usepackage{graphicx}
\\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false]
 {hyperref}

\\makeatletter

\\pdfpageheight\\paperheight
\\pdfpagewidth\\paperwidth
\\theoremstyle{definition}
\\newtheorem{example}{\\protect\\examplename}

\\@ifundefined{date}{}{\\date{}}
\\makeatother

\\providecommand{\\examplename}{範例}

\\begin{document}

\\renewcommand{\\footrulewidth}{0.4pt}
\\thispagestyle{empty}\\tableofcontents{}
\\pagebreak{}
\\renewcommand{\\footrulewidth}{0.4pt}
\\thispagestyle{empty}\\tableofcontents{}
\\pagebreak{}
EOF
cat $TeXfile >> tmpfile
mv -f tmpfile $TeXfile
tex2lyx -f $TeXfile

2024年1月18日 星期四

window dialog using zenity with buttons

zenity --question --width=100 --ok-label="Shutdown anyway" --cancel-label="Cancel" --title="Shutdown reminder" --text="Shutdown now?"
status="$?"
if [ "$status" = 0 ]; then
    zenity --info --width=100 --title="Cancel Shutdown" --text="Cancel Shutdown"
fi
else
  gnome-session-quit --power-off
fi

find hiddent subdir

find ~/.\.* -iname "xxx"
grep -ri dynwall .[^.]*
 

Compress with tar 7z

tar --one-file-system -cf - <dirs> | 7z a -mx=9 -mmt=2 -p -si `date +<filename>%Y%m%d_bsun.tar.7z`


網誌存檔