alias isbashrcmodf='cmp -s "/home/user/.experimental/bc/$(ls /home/user/.experimental/bc -Art | tail -n 1)" "/home/user/.bashrc"'
alias bashrcbak='cp ~/.bashrc ~/.experimental/bc/.bashrc$(date +-%y-%m-%d-%H-%M-%S-%s)'
if isbashrcmodf; then
cd $PWD
else
bashrcbak; echo ".bashrc backed, good to go."
fi
The above script checks the folder /home/user/.expiremental/bc/
for the last modified file (which is previous backup of my .bashrc
) and if the present .bashrc
is different, a backup is made
I possibly want to avoid the if .. then
part and only have if .. else
segment. The cd $PWD
is a hack way of doing nothing which I used since I couldn't find any better doing nothing command.
EDIT :
I just read somewhere a detailed article on how dangerous it is to parse ls
output and rely on ls
, it went on saying that it is safer to use glob along ls
so instead of ls /home/user/.experimental/bc -Art | tail -n 1
it should be :
ls /home/user/.experimental/bc/.bashrc-* -Art | tail -n 1
if .. then
with!$isbashrcmodf
didn't work so any better bash construct you know of that could be used ? Give me examples too, I'm a very slow and dumb learner. – himanshuxd Nov 27 '17 at 17:34