Sponsored Content
Top Forums UNIX for Dummies Questions & Answers ksh script - not getting output from ls Post 302736043 by sudon't on Monday 26th of November 2012 04:27:28 PM
Old 11-26-2012
Quote:
Originally Posted by bakunin
Code:
if [[ ! -d ~/$dir ]]
then
	print "Directory does not yet exist. I will make it so..."
	mkdir ~/$dir
	find ~/$dir -type d -print
else
	print "That directory does exist, as well it should."
	ls ~/$dir
	find ~/$dir -type d -print
fi

The first thing is a general observation: when you write some "if..else..fi" and you end up with commands in both the "if"- and the "else"-branches - they could be placed outside the "if" too, no?
No, I didn't know that. Do you mean, "in the then and else branches"? Although I've read that fi is simply if backwards, I've always read it as finish. You know, like, it's the end. I'm still not entirely clear on how these commands, or arguments, or whatever they're called, work.
But you're saying that I could could just put a single instance of find, or whatever command, after fi, and it'll execute no matter what happens above it? Yeah, ok, I can see that now.

I should also mention that I simply forgot to delete ls ~/$dir, which I intended to do. I like the output of find better, because prints only the path on one line, as opposed to what I was getting, or hoping to get, from ls.

Quote:
The next thing is a minor detail...
No, you're right, especially if we try to make something that might actually be useful. I'm thinking it's possible in many cases that a variable could be handed some white spaces. Do you think it's a good idea to always quote variables, as a matter of course?

Quote:
Next detail: "mkdir" intrinsics.
Right! Again, something I hadn't considered. I tried it, and as you suggest, it did not work. Adding the -p flag fixes it.

Quote:
Last thing: "find" is not necessary in this case.
While I did not try this - at least, not yet - I wonder if cd .. would always work, since it only takes you up one level? For instance, if you had empty directory /Fun, then specified, say, a new directory four levels down: /Fun/X1/X2/X3 Wouldn't cd .. only position you, (and ls), at /X2?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

2. Shell Programming and Scripting

ksh: cmd output to input of another script

I want to write a script in KSH that takes the output of one command and redisplays it. Something like: while true do read inpt date +"%I:%M:%S %p <-> $inpt" done and then some how get the output of the ping command to redirect to the input of this script. does that make sense? (2 Replies)
Discussion started by: IMTheNachoMan
2 Replies

3. Shell Programming and Scripting

ksh script that echo " please insert your name " and store the output to a login.log file.

Hello All Nice to meet you all here in this forum, it's my 1rst time here i'm asking about a little issue that i face i added a ksh script that echo " please insert your name " and store the output to a login.log file. the script is working fine with normal telnet but Xstart is not working... (8 Replies)
Discussion started by: islam.said
8 Replies

4. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

5. Shell Programming and Scripting

ksh script to process grep output

Hi, I would like to know how can i pipe the following output of grep into a predefined output format This is the output of the grep command grep record *.txt | sort -r 2010-04-28-11-12-21.txt:C The user has created a record 2010-04-29-10-18-41.txt:U The user has updated a record... (8 Replies)
Discussion started by: alienated
8 Replies

6. Shell Programming and Scripting

Help with ksh script to display output with specific contents

This is Input - starts with Storage Group Name and ends with Shareable and the loop continues all I need is Storage group name and Alu numbers in the below output format requested. Storage Group Name: abcd Storage Group UID: 00:00:000:00:0:0:0 HBA/SP Pairs: HBA UID ... (6 Replies)
Discussion started by: maddysa
6 Replies

7. Shell Programming and Scripting

Output in for loop (ksh)

Hi , I'm writing the for loop script in home directory and wanted to get the files from /etc/data directory. #!/bin/ksh file_nm="/etc/dat" for test_data in $file_nm/fln* do echo "$test_data" done the code is executing successfully , but in the output it is showing ... (6 Replies)
Discussion started by: smile689
6 Replies

8. UNIX for Dummies Questions & Answers

Executing ksh script to remote server want output on same window

I'm having a brain freeze moment. I've created a ksh script in AIX that ssh's to a remote server, executes some commands, and then logs out. All of this is sent to a file. I then have the script cat the file so i can see the output. Even though the cat command is outside of the remote session part;... (5 Replies)
Discussion started by: seekryts15
5 Replies

9. Shell Programming and Scripting

Line break in sqlplus output through ksh script

Hi, I am new to shell script programming. I have written a ksh script to run the sql File placed in server directory and spool the output in destination directory. Below Command: $ORACLE_HOME/bin/sqlplus -s $ora_uid @$sqlfile_loc$testquery.sql > $opfiledirectory It is generating the output... (6 Replies)
Discussion started by: Sumit Arora
6 Replies

10. UNIX for Beginners Questions & Answers

Passing output parameter(Oracle) to variable in ksh Script

Hello, I have researched and tried many way to pass OUT parameter to be stored in variable in KSH Script.Still not success, please help. Here is my Store Procedure. create procedure testout3(v_in varchar2,v_out OUT integer) as begin v_out := 1; end; Here is my testvout.ksh #!/bin/ksh... (1 Reply)
Discussion started by: palita2601
1 Replies
All times are GMT -4. The time now is 08:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy