How to zero-pad a number in
In order to zero-pad a number you need to use do like below:
Here I have used
As simple as that.
#bash #printf #zeropad #zero-pad #zeropadding
bash?printf is here to help :)In order to zero-pad a number you need to use do like below:
your_number_var=1
output=$(printf "%02d" $your_number_var)
echo $output # 01
Here I have used
%02d. the number 2 refers to numbers of padding and d refers to digit. So to zero-pad to 5 you can use %05d.As simple as that.
#bash #printf #zeropad #zero-pad #zeropadding
If you forget to pull your projects from git in a regular interval and many users working on the same projects, then there is a solution for you!
Create a bash script file as follow and make it executable by
Now as a final step, put it in your crontab:
#linux #git #pull #cronjob #crontab #cron #bash
Create a bash script file as follow and make it executable by
chmod +x puller.sh:puller.sh file content:#!/bin/bash
echo 'Iterating over folders...'
for dir in *
do
test -d "$dir" && {
cd ${dir}
echo "git pull $dir"
git pull
cd ".."
} || {
echo "------> $dir is not a directory <-------"
}
done
NOTE: this file should reside in your folder's project root. In my case it is in /Your/Projects/Folder.Now as a final step, put it in your crontab:
10 * * * * bash -c "cd /Your/Projects/Folder; bash puller.sh >> /var/log/git_pull_output.log"
#linux #git #pull #cronjob #crontab #cron #bash
We have talked before about how to get current month using the below line of code:
It prints out 01, 02, etc.
As per the
So you can remove leading zero by hyphen as below:
It prints out 1, 2, etc.
#linux #bash #date
echo $(date +%m)
It prints out 01, 02, etc.
As per the
GNU date manpage:By default, date pads numeric fields with zeroes. The following
optional flags may follow '%':
- (hyphen) do not pad the field
So you can remove leading zero by hyphen as below:
echo $(date +%-m)
It prints out 1, 2, etc.
#linux #bash #date
In order to enable bash completion in Kubernetes you can usee the below command in linux bash:
Now to test this enter the below command and you should see the completion:
It should be expanded to
#linux #bash #shell #kubernetes #kubectl
source <(kubectl completion bash)
Now to test this enter the below command and you should see the completion:
kubectl cl<TAB>
It should be expanded to
kubectl cluster-info.#linux #bash #shell #kubernetes #kubectl