Sponsored Content
Top Forums Shell Programming and Scripting Files test How to recover a specific variable Post 302981885 by rovf on Wednesday 21st of September 2016 02:58:15 AM
Old 09-21-2016
As for displaying the full path, you have two choices: If you know that the file names are always relative pathes, the easiest is to prepend $PWD/. If this is not the case, or if you want to have the path "cleaned up" by not containing .. elements, you need to convert it to an absolute path explicitly. Google for "how to convert a relative path to an absolute path".

Aside from this, the logic of your script is flawed. You obviously want to treat each file separately, i.e. create for each file some information, whether it is missing or not. You have (at least) two choices to achieve this:

The first ist to output the desired information INSIDE the if-block where you detect that the file is missing. The second one - if, for whatever reason, you want to keep problem DETECTION and problem REPORTING separate, I suggest a completely differnt approach:

Either use two arrays (one containing all the file names, and one containing a code for the problem occuring with each corresponding file, for instance "missing" or "ok"), or alternatively use only one associative array, where the key is the file name and the value is "missing" or "ok".

---------- Post updated at 08:58 AM ---------- Previous update was at 08:50 AM ----------

I just noticed - by re-reading your initial post - that you never indicated which shell you are using, so some of the suggestions (such as associative arrays) I gave might not work in your shell.

Hence, the first step would be that you decide on a certain shell language, before we can discuss, how exactly a problem can be solved.

Common language choices are:

- POSIX shell (most unconvenient to program, but maximum compatibility - this is often used by system administrators who have to manage a network of different Unix flavours or different shell versions)

- bash (chances are highest that, if you ask a colleague, s/he will know it)

- Zsh (IMO most convenient for shell programming)

- ksh (Many people like it; I can't comment on it, because of lack of experience)

I use for most of my shell programming Zsh, because it is really made for programmers, but bash is also a very popular choice.
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Recover deleted files

Is there a Unix tool, like in Novell, to recover accidentally deleted files? (2 Replies)
Discussion started by: kuultak
2 Replies

2. AIX

recover deleted files

How to recover deleted files in AIX ? (1 Reply)
Discussion started by: vjm
1 Replies

3. UNIX for Dummies Questions & Answers

How to test for a specific file size

Hello, In my shell program, I need to test for a specific size of a text file before it can be imported into an oracle table. If the size is less than that number, my program should stop processing. What is the correct command to do this test? Thanks! (1 Reply)
Discussion started by: GEBRAUN
1 Replies

4. Shell Programming and Scripting

Is there a way to recover files deleted using rm command???

Hi All, I just mistakingly deleted some files using rm command.Is there a way to get it back?i work on Solaris 10 Thanks, Kumar (1 Reply)
Discussion started by: kumarsaravana_s
1 Replies

5. UNIX for Dummies Questions & Answers

Recover data from 2 files then combine

Using dd or similar tools to recover data from 2 damaged cdroms, I need a way to then combine the 2 files, 1 from each cd, and make a good file: this all result from finding that certain cd's tops scratch easily even when using the "proper" cd markers, hence making the file useless, however the... (1 Reply)
Discussion started by: saint65
1 Replies

6. UNIX for Dummies Questions & Answers

how to recover deleted files in unix

Hi Experts, by mistake i deleted some files that are very important to the project. is there any way that i can recover those files,there is no backup for that but the details of the file we know. This will be a great help. Thanks (5 Replies)
Discussion started by: namishtiwari
5 Replies

7. UNIX for Dummies Questions & Answers

Recover directory/files in unix

Hi Guys I accidently deleted a directory( and the files in it) in unix using 'rm -rf' :) Is there any procedure/script/command to recover the same? Your help is highly apperciated -thanks Subramanya (1 Reply)
Discussion started by: sgbhat
1 Replies

8. Shell Programming and Scripting

Need to Recover Deleted Files

Hi, By mistake, executed the following command : rm -rf * and ALL files got deleted. But I need to get back these files as they are very very important. Please help me how to recover this file. Its Urgent for me please. Thanks in advance. (6 Replies)
Discussion started by: unx100
6 Replies
HOTSWAPRC(5)							File Formats Manual						      HOTSWAPRC(5)

NAME
hotswaprc - configuration file for hotswap DESCRIPTION
/etc/hotswaprc is the global configuration file for the hotswap utility. It allows system administrators to specify arbitrary shell scripts to be run after a device is inserted, as well as before and after it is removed. Scripts are selected according to the model name retrieved from the device. This is particularly helpful for automatic configura- tion of CD-RW drives, which require SCSI emulation and bypass normal access via the IDE subsystem. hotswaprc is implemented as an Extensible Mark-up Language (XML) application. XML documents are structured using elements of the form <tag-name> content <tag-name>. A Document Type Definition (DTD) describes the possible content of each element. Please refer to the XML specification for more information. The hotswap distribution also contains an example file, doc/hotswaprc.example, which includes the DTD for the configuration file format. ELEMENTS
<hotswap> This is the root element of the document. Each valid hotswaprc must contain exactly one <hotswap> element. The <hotswap> element may contain an arbitrary number of <device> elements. <device> The configuration file contains one <device> element for every device for which scripts are defined. The <device> element is com- posed of the following elements in this order: <name>, <post-insert>, <pre-remove>, <post-remove>. All but <name> are optional. <name> The content of this element is the model identification string of the IDE device the current <device> element refers to. <post-insert> Contains the shell script that is to be executed after the device has been inserted and registered with the kernel. <pre-remove> Contains the shell script that is to be run before hotswap attempts to unregister the device. <post-remove> Contains the shell script that is to be run after the device had been unregistered. REPORT BUGS
Report bugs to t.stadelmann1@physics.ox.ac.uk. AUTHOR
Written by Tim Stadelmann. SEE ALSO
hotswap(1), xhotswap(1). COPYRIGHT
Copyright (c) 2002-2003 Tim Stadelmann. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License (GPL), Version 2 or any later version published by the Free Software Foundation. 26th November 2002 HOTSWAPRC(5)
All times are GMT -4. The time now is 01:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy