f

#### Unifying files and no files.

Is there an idiom that folds the no-files case into the files-exist case so
they can be handled with a single mechanism?

$bash --version GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu) Copyright (C) 2005 Free Software Foundation, Inc.$ ls

$chmod a-x * chmod: cannot access *': No such file or directory$

I could do this

$chmod a-x * 2>/dev/null$

but that just hides the error; there are still two cases (the exit status tells
the tale).  I could do this

$chmod a-x * 2>/dev/null ; :$

but that's more hiding.  This works

$files=$(find . -type f)

$[ -z "$files" ] || chmod a-x $files$

and is, I suppose, good documentation, but it's too much machinery.  This
problem is similar to handling zero-iteration loops in programs, but it's
irratating that

$for i in * ; do chmod a-x$i ; done
chmod: cannot access *': No such file or directory

$doesn't work. Anything else?   0 rvclayton (11) 3/21/2008 3:33:45 AM comp.unix.shell 15484 articles. 3 followers. 4 Replies 1179 Views Similar Articles [PageSpeed] 18 R. Clayton wrote: > Is there an idiom that folds the no-files case into the files-exist case so > they can be handled with a single mechanism? > >$ bash --version
>   GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
>   Copyright (C) 2005 Free Software Foundation, Inc.
>
>   $ls > >$ chmod a-x *
>   chmod: cannot access *': No such file or directory
>
>   $> > I could do this > >$ chmod a-x * 2>/dev/null
>
>   $> > but that just hides the error; there are still two cases (the exit status tells > the tale). I could do this > >$ chmod a-x * 2>/dev/null ; :
>
>   $> > but that's more hiding. The "problem" in your example is that chmod(1) requires files to operate on; a simple chmod a-x without arguments won't work, even if the shell file globbing mechanism would produce an empty argument list instead of taking the * literally. > This works > >$ files=$(find . -type f) > >$ [ -z "$files" ] || chmod a-x$files
>
>   $You could do set -- * [ -f "$1" ]

but I am not sure whether you like that since it does not avoid the test
operation that you seem to dislike.

> and is, I suppose, good documentation, but it's too much machinery.  This
> problem is similar to handling zero-iteration loops in programs, but it's
> irratating that
>
>   $for i in * ; do chmod a-x$i ; done
>   chmod: cannot access *': No such file or directory
>
>   $> > doesn't work. Anything else? A while/read loop find . -type f | while read -r f ; do chmod a-x "$f" ; done

Janis

 0
Janis
3/21/2008 4:51:00 AM
R. Clayton wrote:

>   $chmod a-x * > chmod: cannot access *': No such file or directory As Janis said, the error is due to chmod /always/ expecting an argument. However, you might find the nullglob feature of bash useful sometimes.$ ls
$echo *$ *
$shopt -s nullglob$ echo *

$Note, however, that this does not solve the problem for all those situations where an argument is expected anyway, like eg chmod:$ chmod a-x *
chmod: missing operand after a-x'

This is something that cannot really be avoided, AFAIK.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.

 0
pk
3/21/2008 8:49:37 AM
  The "problem" in your example is that chmod(1) requires files to operate on;
a simple chmod a-x without arguments won't work, even if the shell file
globbing mechanism would produce an empty argument list instead of taking the
* literally.

True, but I was whining more about misbehaving glue code.  Here's another
irritating one what doesn't work:

$find . -type f | xargs chmod a-x chmod: missing operand after a-x' Try chmod --help' for more information.$

although there is a gnu extension that makes it behave:

$find . -type f | xargs --no-run-if-empty chmod a-x$

 0
rvclayton
3/22/2008 12:20:55 AM
R. Clayton wrote:
>   The "problem" in your example is that chmod(1) requires files to operate on;
>   a simple chmod a-x without arguments won't work, even if the shell file
>   globbing mechanism would produce an empty argument list instead of taking the
>   * literally.
>
> True, but I was whining more about misbehaving glue code.

> Here's another irritating one what doesn't work:

Yes, but actually it's the same case as upthread; if the list provided
by find is empty chmod won't get the arguments it expects.

Janis

>
>   $find . -type f | xargs chmod a-x > chmod: missing operand after a-x' > Try chmod --help' for more information. > >$
>
> although there is a gnu extension that makes it behave:
>
>   $find . -type f | xargs --no-run-if-empty chmod a-x > >$
`
 0
Janis
3/22/2008 12:38:00 AM

Similar Artilces:

file extention from file file location

My shell script is changing the file permission of all files in which the script lies.
Hi all, I have written a shell script that works as intended. But one strange thing happens. Whenever I run this script, it removes the execute permission from all the files of the directory where the script is. What can be the reason? Thanks & Regards, Amit On Feb 5, 6:51=A0am, kami...@gmail.com wrote: > Hi all, > > I have written a shell script that works as intended. But one strange > thing happens. Whenever I run this script, it removes the execute > permission from all the files of the directory where the script is. > What can be the reason? > > Thanks &...

Open folder, read file, close file, open new folder, read file close file etc....
Hello, My current directory has several folders within it. Each folder has the same type of file within it. How do i go from the current directory, into one of the folders, edit the file, then come out of the folder, then go into another folder, edit a file then come out of the folder then into a new one etc etc etc. If this does not make sense i apologise and will try to explain my problem a little better. Any help would be much appreciated. Cheers, Phil Phil: I'm not sure it makes sense. Personally I use the mouse and keyboard for doing this. Were you thinking of something else?...

Generic file I/O error, the file is not a valid labview file
Hi, &nbsp; I have created a project in LV 8.0. Now I am&nbsp;getting the following error when I try to open it...'Generic file I/O error, the file xxxxx.vi is not a valid labview file.' I have tried to open all the subvi's used in my application and I am able to open all of them. I found that this condition may occur if the hard disk is full. So I tried to open my vi from another PC but I am getting the same error everywhere. What am I supposed&nbsp; to do ?? Please help me out if anyone has a solution to this... &nbsp; Regards, Divya Hi Mike... Thank you for your reply... I get this error when opening the main vi in my application. I can't recall anything which may have corrupted the file. The earlier version of the main vi of which I had saved&nbsp;a copy does not give any problems while opening.&nbsp;I had made many changes in the next version of my application which is lost now... Do you think that the file may be corrupted? Is there no way to retrieve it? I do have a system&nbsp;running LabView 8.2 and I have tried to open this file with that version. But I am still getting the same error. DivyaMessage Edited by divya on 03-22-2007 10:42 PM Hi Divya, Check if the VI's size is &gt; the one U re stating as Ur earlier version, without that so many changes. If it &gt;, it may not ve got corrupted. Problem could be something else. Else, if it shows some drastically low size ( like too less kb ), then it has got goof...

Q: File Exchange --- posted file not there yet. Should I upload file again?
I posted a file to the file exchange yesterday, but it is not showing up yet. How long does it usuallly take for the file to show up? Should I upload it again or wait? James Tursa James Tursa <aclassyguywithaknotac@hotmail.com> wrote in message <f058j3h10e632t855riru5bocpodhvgu3k@4ax.com>... > > I posted a file to the file exchange yesterday, but it is not showing > up yet. How long does it usuallly take for the file to show up? Should > I upload it again or wait? > > James Tursa It can take a few days depending on workload, holidays/weekends, sick days etc....

how to make a file from the strings in a file and redirect the content to these new files
Here is scenari0 223 files copied to this this one big flat file. now how to make this file to 223 files. further explaination: below is excerpt from that one file under xxxxx you will see @TC_ID: :BIC4007 then another @TC_ID: :BIC40008 and has a 223 time with TC_ID: :BICxxx numbers How do I use such a script that makes a file named BIC40008, then another BIC40007 AND copying the content from line @TC_ID: :BIC40007 till one line before the next TC_ID: :BIC40008 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx @TC_ID: :BIC40007 @TC_TITLE: @ACT_IDS: @AUTHOR: @AUTO: @CLASS: @GROUP_ID: @RELEASES: @T...

Segmentation violation in mex file. How can we debug a mex file? I do not have unix.
Here is the mex code I wrote to read in a tab-delimited file. The mex file = got created but it causes my MATLAB to end abruptly and give the following = error. Can anyone help me where I am going wrong? Please let me know if any= further information is required Abnormal termination: Segmentation violation #include "mex.h" #include "matrix.h" #include <stdio.h> #include<string.h> #include<stdlib.h> =20 void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { =20 FILE *ptr_file; const char **field_names; /* pointers to field names */ char *buf[1024]; char *temp[20]; int count; int i, j, k, l; int date_field, mva_field, qc_load_field, air_field, qc_air_field, oil_= field, qc_oil_field, wind_a_field, qc_wind_a_field, wind_b_field, qc_wind_b= _field, wind_c_field, qc_wind_c_field, tamb1_field, qc_tamb1_field; char *NAME; NAME=3DmxArrayToString(prhs[0]); count =3D 0; //open file to count elements =20 ptr_file =3Dfopen(NAME,"r"); if (ptr_file !=3D NULL) { //skip first 3 lines =20 fgets(buf, sizeof(buf), ptr_file); fgets(buf, sizeof(buf), ptr_file); fgets(buf, sizeof(buf), ptr_file); //start counting no. of elements =20 while(fgets(buf, sizeof(buf), ptr_file) !=3D NULL) count++; fclose(ptr_file); } field_names[0] =3D "date"; field_names[1] =3D "mva&q...

Problems converting *.sas file to a tab delimited file, in Unix environment
Hello May I please ask for your kind help? Unfortunately I don't have any knowldege of SAS. I have a program [I am attaching a copy of this program below] that generates *.sas7bdat files. After I generate a file called abc_out.sas7bdat , I go to the directory where abc_out.sas7bdata is located and type the following command: sas dexport TAB "abc_out.sas7bdat" {I found this command on the Internet, I thought it would generate a tab delimited text file called "TAB"} {Please note that I am typing this command at the Telnet prompt, in Unix environment, as far as I un...

Web resources about - Unifying files and no files. - comp.unix.shell

Unifying theories in mathematics - Wikipedia, the free encyclopedia
The process of unification might be seen as helping to define what constitutes mathematics as a discipline. For example, mechanics and mathematical ...

Why Star Wars is a unifying force
Blockbuster movies are still popular despite an overwhelming array of entertainment choices The Age's Economics Editor Peter Martin explains ...

Royal baby a joyful and unifying force

Why Star Wars is a unifying force (02:36)
Blockbuster movies are still popular despite an overwhelming array of entertainment choices The Age's Economics Editor Peter Martin explains ...

The ties that blind: Tony Abbott never cut it as a unifying national leader
Malcolm Turnbull's prime ministership is a chance to unify Australia by&nbsp;leading from the centre, something Tony Abbott was never able to&nbsp;achieve. ...

Jeffrey Baldwin inquest urges unifying child-protection agencies
Ontario should consider merging its children's aid societies into one co-ordinated agency. That was one of 103 recommendations released Friday ...

Bloc Quebecois members want new leader Mario Beaulieu to adopt a more open, unifying approach - CTV News ...
New Bloc Quebecois Leader Mario Beaulieu was assuring people on Monday that his party is "more united than ever" amid resignations and anger ...

Unifying pension system a monumental breakthrough
Unifying pension system a monumental breakthrough People's Daily Online A State Council meeting presided over by Premier Li Keqiang pledged ...

Banana Republic CMO Talks New 'Mad Men' Collection, Unifying the Brand
Banana Republic's performance has been uneven in recent years as the brand, like siblings Gap and Old Navy, sought to distinguish itself in the ...

In divided S. Africa, anger at new road tolls proves a powerful unifying force - Alaska Dispatch
The ruling ANC pushed through new electronic tolls after years of opposition. It could pay a price in upcoming national elections.

Resources last updated: 3/21/2016 2:39:59 AM