The problem is this line in your ${COMPANYHOME_ROOT}/bashrc_company
file:
export PROMPT_COMMAND='PS1=`echo "\u@\h$PS2"`'
The PROMPT_COMMAND
variable defines a command that should be run before a prompt is shown. In your case, this has been set to setting PS1. So, each time a prompt is shown, your PS1 is being reset to the dwefault value.
I have no idea why anyone would want to do this, but it's simple enough to fix. Either delete that line from ${COMPANYHOME_ROOT}/bashrc_company
or set PROMPT_COMMAND
to something else in your ~/.bashrc
:
PROMPT_COMMAND=""
Вы можете сделать что-то вроде этого:
dir=$1
subdirectories = $(find $dir -type d) # find only subdirectories in dir
for subdir in $subdirectories
do
n_files=$(find $subdir -maxdepth 1 -type f | wc -l) # find ordinary files in subdir and get it quantity
if [ $n_files -eq 4 ]
then
do_something_4
fi
if [ $n_files -eq 3 ]
then
do_something_3
fi
if [ $n_files -lt 3 ]
then
do_something_else
fi
done
Предполагая, что подкаталоги расположены непосредственно в верхнем каталоге:
#!/bin/sh
topdir="$1"
for dir in "$topdir"/*/; do
set -- "$dir"/*.ar
if [ "$#" -eq 1 ] && [ ! -f "$1" ]; then
# do things when no files were found
# "$1" will be the pattern "$dir"/*.ar with * unexpanded
elif [ "$#" -lt 3 ]; then
# do things when less than 3 files were found
# the filenames are in "$@"
elif [ "$#" -eq 3 ]; then
# do things when 3 files were found
elif [ "$#" -eq 4 ]; then
# do things when 4 files were found
else
# do things when more than 4 files were found
fi
done
Или, используяcase
:
#!/bin/sh
topdir="$1"
for dir in "$topdir"/*/; do
set -- "$dir"/*.ar
if [ "$#" -eq 1 ] && [ ! -f "$1" ]; then
# no files found
fi
case "$#" in
[12])
# less than 3 files found
;;
3)
# 3 files found
;;
4)
# 4 files found
;;
*)
# more than 4 files found
esac
done
Ветви кода, которым требуется имя файла, используют "$@"
для ссылки на все имена файлов в подкаталоге или "$1"
, "$2"
и т. д. для ссылки на отдельные файлы. Имена файлов будут путями, включая каталог $topdir
в начале.