Sponsored Content
Full Discussion: Check for file permission
Top Forums Shell Programming and Scripting Check for file permission Post 302890451 by alister on Wednesday 26th of February 2014 10:34:33 PM
Old 02-26-2014
Quote:
Originally Posted by bakunin
The problem is that expanding an array like "${array[*]}" might lead to a line that is longer than "MAXLINE" and/or consisting of more elements than "MAXARGS" allows for.
I'm assuming that by MAXLINE you mean LINE_MAX and that MAXARGS refers to ARG_MAX. In the case of expanding a for-loop's list, neither is relevant.

ARG_MAX limits the size of the command line and environment accepted by the execve system call. The for-loop does not execve the contents of the array; instead, it creates a list and consecutively binds each member to the same identifier.

LINE_MAX is the longest allowable line length (including the terminating newline character) in a text file. Expanding an array into a for-list using "${arr[@]}" does not generate a line or string. That double-quoted parameter expansion, like its positional parameter counterpart, "$@", directly generates a list.

I don't think it's germane, but while we're on the subject of LINE_MAX and sh, POSIX sh exempts shell scripts from this limit:
Quote:
INPUT FILES

The input file shall be a text file, except that line lengths shall be unlimited.
Historical shells may indeed have hardcoded limits, but I suspect that any shell that supports arrays is sufficiently modern to utilize dynamic memory allocation. Virtual memory is almost certainly the actual limit.

I am not advocating against a while-loop. I have nothing against them. Some of my closest friends are while-loops. My point is simply that categorically advising against a for-loop is a bit much; given a modern shell and sufficient memory, the likelihood of a for-loop meltdown is nil.

There also exists the (remote) possiblity that the for-loop mentioned in the OP is the C-like variant supported by ksh93 and bash, which would allow array traversal using a simple index.

Regards,
Alister

Last edited by alister; 02-26-2014 at 11:39 PM..
This User Gave Thanks to alister For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies

2. UNIX for Dummies Questions & Answers

File Permission

Hi, When I listed one directory in Sun, it showed that : -rwsr-xr-x 1 root bsmbin 78004 Oct 21 2004 bsmprsm I don't know meaning of the character "s" in "rws" above. I have searched in Sun admin documents but no result. Would you please explain it ? :) Thank you so much. (1 Reply)
Discussion started by: msg098
1 Replies

3. Shell Programming and Scripting

sftp - permission setting check

Hello, I am doing a transfer of a file from one HP-UX ( umask : 033 ) server to another HP-UX server ( umask : 033 ) and file got transferred sucessfully. However I could see the file permission gets changed at the receiving end. Would like to know the reason for that? Details below: ... (3 Replies)
Discussion started by: jansat
3 Replies

4. Cybersecurity

file permission/acl: 2 users with write access on 1 file...

Hello, i need some help/advice on how to solve a particular problem. these are the users: |name | group | ---------- --------------- |boss | department1 | |assistant | department1 | |employee | department1 | |spy | department2 | this is the... (0 Replies)
Discussion started by: elzalem
0 Replies

5. Shell Programming and Scripting

Command to check the user's permission in UNIX ??

Hi, What is the command to check the user's permission in UNIX ? e.g: user in UNIX is "myuser" The result should be number format. e.g: 755, 644, etc... Thanks.. :) (3 Replies)
Discussion started by: suigion
3 Replies

6. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

7. Shell Programming and Scripting

File permission check in SFTP mode

Hi, I have requirement to get a file from a remote location using SFTP only if the file has read/write permission either to the user or to the group. Currently i m taking the ls of the required file and storing it in a flat file to check the file permission. Please advice is there any... (3 Replies)
Discussion started by: ravin
3 Replies

8. Shell Programming and Scripting

shell script to check permission before copy over

Hi, I am writing some shell script to check the file owner permission whether the write bit is turn on. If it is turn on it will copy the file to the destination else it will just prompt user to change the file and skipping it. However, I am starting getting loss here as I have couple of... (2 Replies)
Discussion started by: wanaka
2 Replies

9. Shell Programming and Scripting

perl script to check read/write/execute permission for 'others'

I want to check access rights permissions not for 'user', not for 'group', but for 'others'. I want to do it by system command in which i want to use 'ls -l' and 'awk' command. I have written the following program : #!/usr/bin/local/perl #include <stdlib.h> system ("ls -l | awk... (1 Reply)
Discussion started by: shubhamsachdeva
1 Replies

10. HP-UX

File permission

Hi, Could you please tell me the OS command to grant as similar to below permission? rwxrwxr-x OS -- HP-UX Regards, Maddy (8 Replies)
Discussion started by: Maddy123
8 Replies
All times are GMT -4. The time now is 11:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy