Help me find 5 mistakes and than solution to thoes mistakes!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



1:#!/bin/bash

2:# Merge symlink files
3:# Author: Damien Clark
4:# Date: 8/Oct/2000
5:# Purpose:
6:#
7:# Merge files from multiple directories into one directory by linking
8:# This script will create links to files from all of the filename arguments
9:# provided on commandline into the current directory, or from the filename
10:# arguments provided on stdin if no filenames provided on command line.
11:#
12:# The script will check the following properties of the file, before linking it:
13:#
14:# : make sure that each filename provided is actually a regular file (not a
15:# directory or symlink or device file)
16:# : make sure that each file is readable
17:# : make sure that the effective user running the script owns the file,
18:# or the effective group is the group owner ofthe file
19:#
20:# The script will also work properly on filenames with spaces. For example:
21:#
22:# /home/clarkd/My Resume.doc
23:#
24:# Usage: $0 [-s] [-c] [ ...]
25:#
26:# -c option -> continue processing even if an error is detected on a file.
27:# Without this option, the script will stop if an error is
28:# detected with a file.
29:#
30:# -s option -> create symbolic links instead of hard links (does not check
31:# if on same filesystem)
32:#
33:# If the script is provided file names as standard input, it can be expressed
34:# as shown in the example below:
35:#
36:# find ~ -type f -print| generatelinks.sh -s
37:#
38:# The command above will create symbolic links to the files found within the
39:# user's home directory, if the file properties match as above.
40:#
41:# If the script is run with filenames provided as command line argument, as
42:# shown in the example below:
43:#
44:# generatelinks.sh /home/clarkd/*.doc /home/clarkd/documents/*.doc
45:#
46:# without the ! -c option, then the script will ask to confirm whether to continue
47:# not to continue, or to continue for all.

48:#Process each file and link it if it is okay.
49:processfile
50:{
51: lnopts="$1"
52: filename="$2"

53: #file must be "normal file"
54: if [ ! -f "$filename" ]
55: then
56: echo Not a normal file: $filename
57: retval=1
58: #must have "read perms"
59: elif [ ! -r "$filename" ]
60: then
61: echo "No read permissions: $filename"
62: retval=1
63: #user must either effective owner the file or effective group owner of the file
64: elif [ ! -O "$filename" -o ! -G "$filename" ]
65: then
66: echo "No effective ownership or effective group ownership of file: $filename"
67: retval=1
68: #Otherwise all is well, link the file to current directory using existing name
69: else
70: ln $lnopts $filename
71: retval=$?
72: fi

73: #Return the exit status code > 0 if a problem occured
74: return $retval
75:}

76:# Initialise variables
77:cont='N'
78:lnopts=''

79:# Process switches
80:while test "$1" = '-c' '-o' "$1" = '-s'
81:do
82: if [ "$1" = '-c' ]
83: then
84: cont='Y'
85: shift
86: fi
87: if [ "$1" = '-s' ]
88: then
89: lnopts='-s'
90: shift
91: fi
92:done

93:echo "Commencing generation of files

94:if [$# -lt 1]

95: while read filename
96: do
97: processfile "$lnopts" "$filename"
98: result=$?

99: test $result -ne 0 -a "$cont" != 'Y' -a "$cont" != 'y' || exit 1
100: done

101:else

102: for filename in $*
103: do
104: processfile "$lnopts" "$filename"
105: result=$?

106: if [ $result -ne 0 -a "$cont" != 'Y' ]
107: then
108: echo -n "Error occurred. Continue (y/n/a)? "
109: read $cont

110: test "$cont" = 'n' -o "$cont" = 'N' && exit 1
111: [ "$cont" = 'a' || "$cont" = 'A' ] && cont='Y'
112: fi
113: done

114:fi

115:echo "All files processed"

Hints/Tips

? There is only one mistake per line.
? ALWAYS include the line number, the description of the problem and your solution.


Do you Yahoo!?
Y! Messenger - Communicate in real time. Download now.

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux