How to handle parameters in a .bashrc function
I want to create a simple bash function (in .bashrc) that takes in one parameter (a directory name) and tars all the files inside of that directory into a specific directory in /home (we'll call that destdir). The name of the tar should be the same as the directory parameter.
For example, I want to be able to type into the terminal "task directory_name". I tried this but it didn't work: Code:
function_name() { |
Try it by taking out the / in the /~/destdir part. ~/destdir should be sufficient.
Also, trying creating a shell script from that function and use bash -x to diagnose the issue further if the above doesn't help |
Code:
function_name() { N.B. Won't handle folders with spaces in their names in ( that's for you too work out) ~/destdir must exist if it doesn't again for you to work out. See the man page for tar an the advanced bash scripting guide for detailed help |
Quote:
|
SNAP! Ah no worries :)
|
Code:
function_name() { |
Quote:
Yes lots of error checking can be done but leave something for the OP to do! :) My excuse is I was typing on my tablet and couldn't actually test the code! |
All times are GMT -5. The time now is 07:35 PM. |