Bash Scripting

Aus virengos.org wiki
Zur Navigation springen Zur Suche springen

Bash Snippets

If Statements

if [ -f $folder_destin"SALOME"*.tar.gz ]; then
	echo "*** Salome files already exists in the defined folder ***"
	echo "*** delete existing files and restart this script! ***"
	exit
fi
if [ ! -d "$i" ]; then
        second_name=`echo $i | sed 's/\///'`
        echo "      $i : $second_name" >> snapcraft.yaml
fi

Loops

  • Find files // iterate over results // skip characters
find . -maxdepth 1 -mindepth 1 -type d -name "*"|while read fname; do
    # skip first character
    do_dir=$current_sim_dir${fname:1}
    # skip characters at start and end
    do_dir2=$current_sim_dir${fname:2:-3}
    echo "(1) "$do_dir "(2)" $do_dir2
done