Monday, January 25, 2016

scripts - How do I use command line arguments in bash?

This script moves all the doc files to a specified directory. I have managed to put an argument but the problem I am facing is putting the full path where the scripts are moving to, for example I want to run the script like this below


./loo -d then path where im moving the files (i.e ./loo -d the second argument where files are moving to)

this is my code


#!/bin/bash
From="/home/elg19/lone/doc"
To="/home/elg19/documents"
if [ $1 = -d ]; then
cd "$From"
for i in pdf txt doc; do
find . -type f -name "*.${i}" -exec mv "{}" "$To" \;
done
fi

No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...