Extract File name in bash:-
You can use basename
to Strip directory and suffix from filenames
for i in /tmp/files/*/*; do
key=$(basename $i)
Add Date in File or folder Name:-
In case you have requirement of adding date in your file or folder name
now=$(date +"%m-%d-%Y")
printf "%s\n" $now
User Input:-
read
command can be used to take input from user.
read -p "Please input $inp? [yn]" answer
if [[ $answer = y ]] ; then
# run the command
echo "Yes"
fi
Use set -x to watch execution
By default, after the script is executed, it only displays the results. You can use set -x
to output the executed command line before its execution result.
root@bd92bbce2f7d:/# cat dummy.sh
#!/usr/bin/env bash
set -x
echo Step 1
echo Step 2
root@bd92bbce2f7d:/# sh dummy.sh
+ echo Step 1
Step 1
+ echo Step 2
Step 2
I will keep updating this post, if I find something useful. Thanks
Top comments (0)