if [ -z "$1" ] ; then and if [ $# -lt 1 ]; then are basically the same.
I added the required extensions for you, hope you will like it. It's rather a quick & dirty hack than how it should be done in a professional manner. I mean it should be done using getopts.
if [ -z "$1" ] ; then and if [ $# -lt 1 ]; then are basically the same.
I added the required extensions for you, hope you will like it. It's rather a quick & dirty hack than how it should be done in a professional manner. I mean it should be done using getopts.
Thank you !! Now can i try implement other parameters
---------- Post updated at 11:56 AM ---------- Previous update was at 11:48 AM ----------
Quote:
Originally Posted by Roggy
Thank you !! Now can i try implement other parameters
i have done it to implement other parameters but i have one question that I not understand in the script what means and what does dswitch , I don't understand it because it is my first time I do bash scripting
dswitch=1 literally means that value 1 is assigned to the variable dswitch, but I used that variable name to "remember" that the script was started with the "-d" option. One could interpret it as "script started with -d option?"="YES".
It's related to the second if statement in the for loop, which decides if all subfolders of a specific directory need to be shown too or not.
dswitch=1 literally means that value 1 is assigned to the variable dswitch, but I used that variable name to "remember" that the script was started with the "-d" option. One could interpret it as "script started with -d option?"="YES".
It's related to the second if statement in the for loop, which decides if all subfolders of a specific directory need to be shown too or not.
Thank you very much, but what must I change for give one parameter ?
I want to give ./test1.sh Desktop only first and then I want to give two directories ./test1.sh Documents Desktop and then the parameters I implement -d -f
Is this the line I have to changed ? Into if [$# -lt 1 ] ?
There have been a couple of suggestions saying that you should use getopts to parse options (and I STRONGLY agree). Unfortunately, as far as I know, getopts in bash can't handle long options. Although it isn't often described in the man pages, getopts in many version of the Korn shell works well with both short and long options as long as there is a single letter equivalent for each long option. The following is a rewrite of your script using ksh instead of bash and using getopts instead of discrete option parsing. This doesn't make a lot of difference in your code since you only have one option that can be logically used at a time; but it does give you the ability to use -- as an option terminator in case you have a directory operand that starts with a -, and, if you add more options later, groups of short options that don't take option arguments can be combined into a single argument to your script (the same as allowed by standard utilities).
After parsing options this script will print the number of operands remaining, list them, and then process them as directory operands.
You haven't said what OS you're using, so this might not work on your system, but it is worth a try...
When invoked as:
it produces the output:
on standard output and exits with exit code 0.
When invoked as:
on my system, it currently produces the output:
And, if invoked as:
it produces the output:
followed by the help screen (all written to standard error output instead of to standard output) and exits with exit code 1.
This User Gave Thanks to Don Cragun For This Post:
what is the best way to move the contents of a folder to another one without deleting the structure of the first one. the contents could include subfolder too.
both folder, the source-folder and the target-folder are on the same host.
any idea is appreciated . (7 Replies)
for dir in BKP/*/
do
echo You are in :$dir
done
O/P
--
BKP/201448/
BKP/201449/
BKP/201450/
BKP/201451/
BKP/201452/
BKP/201501/
BKP/201502/
BKP/201503/
BKP/201504/
BKP/201505/
BKP/201506/
BKP/201507/ (3 Replies)
Hi one of the output of the command is as below
# sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/'
Resource List : <br>
*************************** 1. row ***************************<br>
... (2 Replies)
Hi experts,
I am coming to you with this basic question on copying a folder and its content from one location to another folder using PERL script.
This is my requirement.
I have a folder AB under /users/myhome
I want to copy AB and its contents to /user/workspace.
Finally it should... (1 Reply)
I am working on HP Unix. Require a script for the below requirement.
Requirement are:
1. Need to create a folder with files.
2. The folder should have a naming convention like - LRIC_ARCHIVE_ddmmyyhhmmss_version_nnn, the version number needs to be selected from an oracle table.
3. When the... (4 Replies)
I use diff -r dir1 dir2 to get comparison of two folders that are on same machine.
Now I need the same thing but one of the folders is on a different machine.
Currently I ftp the folder to a temp folder compare using above command and delete the temp folder.
Is there any other better options?... (5 Replies)
Hello everyone....
I have a small issue here at work and I am trying to script out a way to automate a fix for it. I have a small number of users (I work in a 1:1 with 6,000 macbooks) that aren't really managed in my deployment. They are managed with a few policies, but the policies are broken... (2 Replies)
Hi,
I am a new learner of Unix. I am currently working on a Solaris 8 machine. Earlier, when I use 'cd <folder name>' command, I am not only able to change the folder but also able to see the contents of the folder as if a 'ls -lt' command was executed. However, since a week, suddenly this... (3 Replies)
I need to make a new dir in side the dir lab5 the new dir is called testLab5
without changing directories copy all files from your lab5 directory into your testLab5 directory
then i have to
without chaning directories and using exactly one command remove all files that start with the... (1 Reply)
Hi,
I'm trying to allow people to access the contents of a folder on a web site, I am automatically placing files in this folder for people to download. I'm using Apache on Mac OS X, if that makes a difference.
Can anyone help with this? I've found no documentation on this so far...
... (6 Replies)