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
Is there a Unix tool, like in Novell, to recover accidentally deleted files? (2 Replies)
Discussion started by: kuultak
2 Replies
2. AIX
How to recover deleted files in AIX ? (1 Reply)
Discussion started by: vjm
1 Replies
3. UNIX for Dummies Questions & Answers
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
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
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
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
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
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
SCRIPT(1) User Commands SCRIPT(1)
NAME
script - make typescript of terminal session
SYNOPSIS
script [options] [file]
DESCRIPTION
script makes a typescript of everything displayed on your terminal. It is useful for students who need a hardcopy record of an interactive
session as proof of an assignment, as the typescript file can be printed out later with lpr(1).
If the argument file is given, script saves the dialogue in this file. If no filename is given, the dialogue is saved in the file type-
script.
OPTIONS
-a, --append
Append the output to file or to typescript, retaining the prior contents.
-c, --command command
Run the command rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves
differently when its stdout is not a tty.
-e, --return
Return the exit code of the child process. Uses the same format as bash termination on signal termination exit code is 128+n.
-f, --flush
Flush output after each write. This is nice for telecooperation: one person does `mkfifo foo; script -f foo', and another can
supervise real-time what is being done using `cat foo'.
--force
Allow the default output destination, i.e. the typescript file, to be a hard or symbolic link. The command will follow a symbolic
link.
-q, --quiet
Be quiet (do not write start and done messages to standard output).
-t[file], --timing[=file]
Output timing data to standard error, or to file when given. This data contains two fields, separated by a space. The first field
indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time.
This information can be used to replay typescripts with realistic typing and output delays.
-V, --version
Display version information and exit.
-h, --help
Display help text and exit.
NOTES
The script ends when the forked shell exits (a control-D for the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not
set) for the C-shell, csh(1)).
Certain interactive commands, such as vi(1), create garbage in the typescript file. script works best with commands that do not manipulate
the screen, the results are meant to emulate a hardcopy terminal.
It is not recommended to run script in non-interactive shells. The inner shell of script is always interactive, and this could lead to
unexpected results. If you use script in the shell initialization file, you have to avoid entering an infinite loop. You can use for
example the .profile file, which is read by login shells only:
if test -t 0 ; then
script
exit
fi
You should also avoid use of script in command pipes, as script can read more input than you would expect.
ENVIRONMENT
The following environment variable is utilized by script:
SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed.
(Most shells set this variable automatically).
SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1)
HISTORY
The script command appeared in 3.0BSD.
BUGS
script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects.
script is primarily designed for interactive terminal sessions. When stdin is not a terminal (for example: echo foo | script), then the
session can hang, because the interactive shell within the script session misses EOF and script has no clue when to close the session. See
the NOTES section for more information.
AVAILABILITY
The script command is part of the util-linux package and is available from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils
/util-linux/>.
util-linux June 2014 SCRIPT(1)