I have a script with logic like:
so basically it will make a directory for every name in the list and create a directory with the date appended (which I only want to do once). What I want to know is how do I perform the line "mkdir mydir_${2}" only once? This is not the script itself, so this example it a bit silly, but the logic is there, I want to iterate through a list and call a function with each item in the list, but there is one element in the function that should only happen once.. Assume that the argument $2 is something that will not change through each iteration, so I do not want to repeat the process doing the same thing over and over. Is there a better solution than to create another function and call it? There is a reason that I dont move this line out of the function, but it's difficult to explain without posting my company's intellectual property.
Another question, is it possible to, in a for-loop incrementing until it reaches a certain number, to have it loop again without incrementing? Just have it drop what it is doing when it reaches this command and start again at the same number it was at? I know I could make a while loop and just... (0 Replies)
Hi All,
I amlearning UNIX scripting. I have a small query. I would be thankful if any one helps me out.
I have a below piece of code which delets the files. If file dosent have the permissions to delete a particular file I have used 2>>operator to track the error code.
But my objective is... (1 Reply)
I wonder how to stop further loop iterations when conditions gets false e.g.
This file.txt contains the following structure :
1
2
3
4
5
6
7
8
9
10
How to stop iteration when if statement gets false ?
for n in `cat file.txt`
do
if (( n<=5 )) (1 Reply)
question :how can i iterate to next item in for loop with the loop
e.g
for i in `cat abc.txt`
do
echo $i // this will display first line
i=$i+1; // this doesnt work for me.
echo $i; //this will display secound line
done
question: is my approach to manipulate text good?
I have... (3 Replies)
I have written the following script to update some Debian boxes.
#!/bin/bash
mxg_hosts_file="/etc/mxg/ssh-hosts"
while read line ; do
mxg_host="$(echo ${line} | awk -F":" '{print $1}')"
mxg_port="$(echo ${line} | awk -F":" '{print $2}')"
echo "Connecting and Upgrading... (3 Replies)
for VGLIST in `lsvg -o`
do
CLOSED_OUT=`echo $VGLIST | lsvg -l $VGLIST | awk '{print $6 " " $7}' | grep closed`
if ]; then
echo "Filesystems $CLOSED_OUT in VG that are in Closed status"
else
echo "\n Some message"
fi
Above Code is working fine, but echo "Filesystems $CLOSED_OUT... (8 Replies)
bash in RHEL 6.4
I have a requirement in which I want to get the iteration count from a WHILE LOOP.
The below mentioned simple script test.sh works fine. In the below script, the WHILE loop will iterate every 5 seconds infinitely until it greps the string BASKETBALL from /tmp/somestring.txt... (6 Replies)
I am trying to check multiple server's "uptime" in a loop over "ssh".
When I execute multiple ssh commands with hard coded servernames script is executing fine.
But when I pass server names using while loop, script is exiting after checking first server's status, why?
# serverList... (8 Replies)
Hello,
I have been stuck on this for some time and invested many hours trying to find a solution. I am trying to either loop through two variables or or two arrays and not sure how to do it. I am limited to ksh only, and don't have the ability to do a foreach, or for i AND for j etc...I... (19 Replies)
Hello,
I've written a script to automate encoding of all the MP4 files in a directory (incl. subdirectories). But unfortunately it's running for the first MP4 file only.
My machine details:
root@Ubuntu16:~# uname -a
Linux Ubuntu16 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48... (2 Replies)
Discussion started by: prvnrk
2 Replies
LEARN ABOUT OPENSOLARIS
mkdir
mkdir(1) User Commands mkdir(1)NAME
mkdir - make directories
SYNOPSIS
/usr/bin/mkdir
/usr/bin/mkdir [-m mode] [-p] dir...
ksh93
mkdir [-p] [-m mode] dir...
DESCRIPTION
/usr/bin/mkdir
The mkdir command creates the named directories in mode 777 (possibly altered by the file mode creation mask umask(1)).
Standard entries in a directory (for instance, the files ".", for the directory itself, and "..", for its parent) are made automatically.
mkdir cannot create these entries by name. Creation of a directory requires write permission in the parent directory.
The owner-ID and group-ID of the new directories are set to the process's effective user-ID and group-ID, respectively. mkdir calls the
mkdir(2) system call.
setgid and mkdir
To change the setgid bit on a newly created directory, you must use chmod g+s or chmod g-s after executing mkdir.
The setgid bit setting is inherited from the parent directory.
ksh93
The mkdir built-in in ksh93 is associated with the /bin and /usr/bin paths. It is invoked when mkdir is executed without a pathname prefix
and the pathname search finds a /bin/mkdir or /usr/bin/mkdir executable. mkdir creates one or more directories. By default, the mode of
created directories is a=rwx minus the bits set in umask(1).
OPTIONS
/usr/bin/mkdir
The following options are supported by /usr/bin/mkdir:
-m mode This option allows users to specify the mode to be used for new directories. Choices for modes can be found in chmod(1).
-p With this option, mkdir creates dir by creating all the non-existing parent directories first. The mode given to intermediate
directories is the difference between 777 and the bits set in the file mode creation mask. The difference, however, must be at
least 300 (write and execute permission for the user).
ksh93
The following options are supported by the mkdir built-in in ksh93:
-m mode Set the mode of created directories to mode. mode is symbolic or octal mode as in chmod(1). Relative modes assume an initial
--mode=mode mode of a=rwx.
-p Create any missing intermediate pathname components. For each dir operand that does not name an existing directory, effects
--parents equivalent to those caused by the following command shall occur:
mkdir -p -m $(umask -S),u+wx
$(dirname dir) && mkdir [-m mode] dir
Where the -m mode option represents that option supplied to the original invocation of mkdir, if any. Each dir operand that
names an existing directory is ignored without error.
OPERANDS
The following operand is supported:
dir A path name of a directory to be created.
USAGE
See largefile(5) for the description of the behavior of mkdir when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
EXAMPLES
Example 1 Using mkdir
The following example:
example% mkdir -p ltr/jd/jan
creates the subdirectory structure ltr/jd/jan.
ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of mkdir: LANG, LC_ALL, LC_CTYPE, LC_MES-
SAGES, and NLSPATH.
EXIT STATUS
The following exit values are returned:
0 All the specified directories were created successfully or the -p option was specified and all the specified directories now exist.
>0 An error occurred.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
/usr/bin/mkdir
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
|CSI |Enabled |
+-----------------------------+-----------------------------+
|Interface Stability |Committed |
+-----------------------------+-----------------------------+
|Standard |See standards(5). |
+-----------------------------+-----------------------------+
ksh93
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
|Interface Stability |See below. |
+-----------------------------+-----------------------------+
|Standard |See standards(5). |
+-----------------------------+-----------------------------+
The ksh93 built-in binding to /bin and /usr/bin is Volatile. The built-in interfaces are Uncommitted.
SEE ALSO chmod(1), ksh93(1), rm(1), sh(1), umask(1), Intro(2), mkdir(2), attributes(5), environ(5), largefile(5), standards(5)SunOS 5.11 2 Nov 2007 mkdir(1)