Use one loop to handle below code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use one loop to handle below code
# 1  
Old 12-18-2012
Use one loop to handle below code

Code:
 mknod /dev/vda b 253 0
 mknod /dev/vda1 b 253 1
 mknod /dev/vda2 b 253 2
 mknod /dev/vda3 b 253 3

I know below code is ease to handle, but I don't know above code
Code:
 mknod /dev/vda1 b 253 1
 mknod /dev/vda2 b 253 2
 mknod /dev/vda3 b 253 3

# 2  
Old 12-18-2012
Using BASH:-
Code:
#!/bin/bash

for SEQ in {0..3}
do
        if [ $SEQ -eq 0 ]
        then
                mknod /dev/vda b 253 $SEQ
        else
                mknod /dev/vda${SEQ} b 253 ${SEQ}
        fi
done

# 3  
Old 12-18-2012
Here is another way to do it that only uses shell behavior required by the POSIX standards:
Code:
#!/bin/ksh
i=0
while [ $i -le 3 ]
do      mknod /dev/vda${i#0} b 253 $i
        i=$((i + 1))
done

The construct for i in {0..3} is available in a some shells, but is an extension that is not specified by the standards.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 12-18-2012
In reality you would do
Code:
mknod /dev/vda0 b 253 0

and finally create the shortcut
Code:
ln -s vda0 /dev/vda

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Handle color code

p1=text1 p2=text2(in red color) when i am trying to replace $p1 with $p2, content of the file from text2 become red. so when i open that file using vi its showing color code before tex2. please suggest me how to omit that color code and make content of that file in default color? (1 Reply)
Discussion started by: Biplab
1 Replies

2. Shell Programming and Scripting

How to Return to a While Loop From The Bottom of Code?

Hello All, I was wondering how after processing a program down to the bottom of the program one can return to the only while loop in the program. Thanx, (5 Replies)
Discussion started by: techieg
5 Replies

3. UNIX for Dummies Questions & Answers

Nested loop code

Greetings, Would anyone be able to tell me why this nested loop doesn't seem to work in any variation? for i in {1..8} do echo "i is "$i for j in {1..i} do echo "j is "$j done doneoutput is always along the lines of i is 1... (7 Replies)
Discussion started by: barnhillec
7 Replies

4. UNIX for Dummies Questions & Answers

Difference between handle to the thread HANDLE and thread identifier pthread_t

This question might be silly but its confusing me a bit: What is the difference between handle to the thread HANDLE and thread identifier pthread_t? ---------- Post updated at 01:52 PM ---------- Previous update was at 01:48 PM ---------- Sorry I saw details and HANDLE is in windows and... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

5. Shell Programming and Scripting

Need code to ftp files in loop

I have files like this beginning from 082008 (MMYYYY) to 112010 (MMYYYY) I need to fetch this files through ftp in loop. How can I achieve it? I tried with the following code. But I'm not sure how to increment the month from 082008 to 112010. for i in {082008 .. 112010} ... (5 Replies)
Discussion started by: Gangadhar Reddy
5 Replies

6. UNIX for Dummies Questions & Answers

Understanding Code in IF LOOP

Hello All, I would like to know and understand the difference between the below 3 IF loops and also if possible what are the different other parameters i could use other than those mentioed in the below lF LOOP conditions, appreciate your help. Thanks, Sam. (1 Reply)
Discussion started by: Ariean
1 Replies

7. Programming

Is my code in an Infinite Loop?

Production C code compiled without the dash-g option is running, and seems to be in an infinite loop. Is there a way to tell? Is there a diagnostic tool that will report what objects or what lines of code or even what functions are being executed? Or is my best option to kill it with a dump? ... (5 Replies)
Discussion started by: marcus121
5 Replies

8. Shell Programming and Scripting

Loop certain code to all files within directory

Hi all, Can somebody help me with this problem pls. I need to extract one specific line from each files in a folder and put the all lines extracted in a unique output file in the following format. line extracted, respective name of file, date of file. I´m, trying the part to extract... (3 Replies)
Discussion started by: cgkmal
3 Replies

9. Shell Programming and Scripting

need loop clarification for the below code

for loop for string to check each path file count. can someone please help me out regarding this.. purpose is that it will gives the number of files inside the that directory.. i am bit confused in doing the loop for the above can someone plz fix. PATH1=/home/data1 PATH2=/home/data2... (2 Replies)
Discussion started by: mail2sant
2 Replies

10. Shell Programming and Scripting

the given code goes in infinite loop and does not increment variable i

code is as #!/bin/sh i=1; while do welcome $i times; i='expr $i+1'; done exit 0; (6 Replies)
Discussion started by: mrityunjay22
6 Replies
Login or Register to Ask a Question