A difficult script (for me)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A difficult script (for me)
# 1  
Old 01-07-2008
Question A difficult script (for me)

Hi,
I'm a beginners, this is one of my first script, it's easy, but I don't know how to write this script:

The script receive in input 4 parameters:
1) user_name
2) r and/or w and/or x ( rwx, rw, x, ....)
3) u and/or g and/or o ( u, uo, ugo, ...)
4) the path name

The script print a list of normal files ( “-” with ls) created by user_name, with at least the permission specified as 2nd parameters for the groups specified as 3rd parameter , starting from the path name passed as 4th parameter.

Example of permission:
giving: rw, u
I look for “ rw-......“ using ls -lr (. is a generic character)
giving: rw, ugo
I look for “ rw-rw-rw- “

I tryed in many ways, but for example i f I execute a simple script like this:
permission=-rw-r--r--
ls -lR | grep '^-$permission'

The script don't print anything on the screen, but I type in the shell:
ls -lR | grep '^-rw-r--r--'
the output is correct.

Moreover I don't know how to separate the colums of ls -lR using CUT (I suppose) to select oly the rows that are created by the user

So I understood I need help. Please help me.
PS: i have to write many script, and this is the simplest, so if I don't know how to write this, I'll never be able to write the others..

Last edited by DNAx86; 01-07-2008 at 01:36 PM..
# 2  
Old 01-07-2008
First, you won't get variable substitution inside single-quotes:

Code:
# x=123
# echo 'x=$x'       # string is literal
x=$x

# echo "x=$x"       # string is evaluated by the shell
x=123

# echo "x='$x'"
x='123'

Single-quotes lose their special quoting superpowers when inside double-quotes.

Also, if you pass a string to a command that includes a dash ("-") you run the risk of the string being interpreted as flags. You should therefore use the double-dash to indicate that no more flags are coming:

Code:
grep -c -v -- "$string" $file

So if "$string" includes any dashes, they will be ignored since they are after the "--".
# 3  
Old 01-07-2008
Quote:
Originally Posted by gus2000
First, you won't get variable substitution inside single-quotes:

Code:
# x=123
# echo 'x=$x'       # string is literal
x=$x

# echo "x=$x"       # string is evaluated by the shell
x=123

# echo "x='$x'"
x='123'

Single-quotes lose their special quoting superpowers when inside double-quotes.

Also, if you pass a string to a command that includes a dash ("-") you run the risk of the string being interpreted as flags. You should therefore use the double-dash to indicate that no more flags are coming:

Code:
grep -c -v -- "$string" $file

So if "$string" includes any dashes, they will be ignored since they are after the "--".
Thanks.

Now, I don't know how to separate the colums of ls -lR using CUT (or using another command) to select oly the rows that are created by the user
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Been working since 25+ hrs: Bash Script to rename files supposedly direct but difficult to execute

:wall::wall::wall: Hi I have horrible script below, need help in renaming ls -l output into new filename format: Desired output: cp -pv original_path/.* newDirectory/owner_of_file.%dd%mm%y.file_extension.first_8_characters_of_original_filename localuser@localuser:~ vi... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

2. Shell Programming and Scripting

Shell script menu for end user - difficult challenge 2

Hello, I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu. Example, when user will run main menu script, it will get something like this on his screen:... (1 Reply)
Discussion started by: waso
1 Replies

3. Programming

Difficult in analyzing an algorithm

Hello, I was reading Heuritics text and came across an algorithm below. Finding hard to analyze it can any one help me out below... How to analyze if I take say no. of types are 5 and each type has say 20 coins. thanks. Let {c1, c2...cn=1} be a set of distinct coin types where ci is... (1 Reply)
Discussion started by: sureshcisco
1 Replies

4. Shell Programming and Scripting

Shell script menu for end user - difficult challenge

Hello, I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu. Example, when user will run main menu script, it will get something like this on his screen:... (3 Replies)
Discussion started by: waso
3 Replies

5. Shell Programming and Scripting

Difficult problem: Complex text file manipulation in bash script.

I don't know if this is a big issue or not, but I'm having difficulties. I apoligize for the upcoming essay :o. I'm writing a script, similar to a paint program that edits images, but in the form of ANSI block characters. The program so far is working. I managed to save the image into a file,... (14 Replies)
Discussion started by: tinman47
14 Replies

6. Shell Programming and Scripting

difficult nawk to understand

I found a command who prints x lines before and after a line who contain a searched string in a text file. The command is : nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=2 a=4 s="string" file1 It works very well but I can't understand the syntax, too difficult with... (2 Replies)
Discussion started by: ahmad.diab
2 Replies

7. UNIX for Dummies Questions & Answers

so difficult question about using grep

en...how to grep some words from some file, the goal is that, we donot want the words are exactly 9 charactor, and want to grep from some words that are longer than 9 and it contain a substring that with 9 different charactors (2 Replies)
Discussion started by: shrimpy
2 Replies

8. UNIX for Advanced & Expert Users

difficult sed command

Im trying to replace every line line1 line2 line3 with: line1 extraline1 line2 extraline2 line3 extraline3 with about 10 extra lines I am able to add axtra lines with: (17 Replies)
Discussion started by: Dave724001
17 Replies

9. Solaris

difficult time differences

:rolleyes: Hi, How to take the time diffence between start and finish time from a log file? It is like ..... started at Jun 20 23:20 . . ..... finished at Jun 21 01:40 Tryed so many ways but failed to ger exact way. :confused: Your help will be honoured. Ta........Lokesha (1 Reply)
Discussion started by: Lokesha
1 Replies

10. UNIX for Advanced & Expert Users

Difficult Filtering Problem

Sir, I have a file containing say 1000 lines that contain 100 paragraphs of 10 lines each separated by blank lines.I have to match a pattern or a string "hdfhasdjkasdhs" and print the complete paragraphs containing these strings.I can do this with the help of line editor ex,but how can I use... (1 Reply)
Discussion started by: Piyush
1 Replies
Login or Register to Ask a Question