Greetings, Been struggling for a while trying to figure out why my script keeps removing the hidden directories: When you run ls -l as a user you get a listing without the .xxxxx files, But as root ls -l shows all anyway. So when root runs the script it deletes everything in the folder. I assumed there was an alias runnng for ls but can't find it. Can someone here please assist Thanks Chadley
On Thursday 24 November 2005 08:23, Chadley Wilson wrote:
Greetings,
Been struggling for a while trying to figure out why my script keeps removing the hidden directories:
When you run ls -l as a user you get a listing without the .xxxxx files, But as root ls -l shows all anyway.
So when root runs the script it deletes everything in the folder.
I assumed there was an alias runnng for ls but can't find it.
Can someone here please assist
Thanks Chadley
Did you post the script - I don't seem to have it here. Perhaps post it again in the body of the text? Best Fergus
On Thursday 24 November 2005 08:23, Chadley Wilson wrote:
Greetings,
Been struggling for a while trying to figure out why my script keeps removing the hidden directories:
When you run ls -l as a user you get a listing without the .xxxxx files, But as root ls -l shows all anyway.
So when root runs the script it deletes everything in the folder.
I assumed there was an alias runnng for ls but can't find it.
Can someone here please assist
Thanks Chadley
Now I look, the 'env' for a default user shows this variable set: LS_OPTIONS=-N --color=tty -T 0 Whereas for root, 'env' shows: LS_OPTIONS=-a -N --color=tty -T 0 So the 'ls -a' for root is coming from there. I'm just casting about trying to find out where that variable is set - first person to send a link to a thorough discussion of SuSE's bash variables gets a lollipop. But you could perhaps put something in your script that unsets that part of the variable. export LS_OPTIONS= zeroes it out and stops the ls -a behaviour for the remainder of the session. Should your script be in bash? It used, at least, to be practice to run a lot of shells as sh, and indeed if you change to sh you'll notice ls doesn't list dotfiles. How about having a go with your script with sh as the shell? IIRC putting #!/bin/sh at the top of the file should do it. HTH Fergus
On Thu, 2005-11-24 at 09:13 +0000, Fergus Wilde wrote:
On Thursday 24 November 2005 08:23, Chadley Wilson wrote:
Greetings,
Been struggling for a while trying to figure out why my script keeps removing the hidden directories:
When you run ls -l as a user you get a listing without the .xxxxx files, But as root ls -l shows all anyway.
So when root runs the script it deletes everything in the folder.
I assumed there was an alias runnng for ls but can't find it.
Can someone here please assist
Thanks Chadley
Now I look, the 'env' for a default user shows this variable set:
LS_OPTIONS=-N --color=tty -T 0
Whereas for root, 'env' shows:
LS_OPTIONS=-a -N --color=tty -T 0
So the 'ls -a' for root is coming from there. I'm just casting about trying to find out where that variable is set - first person to send a link to a thorough discussion of SuSE's bash variables gets a lollipop.
But you could perhaps put something in your script that unsets that part of the variable.
export LS_OPTIONS= ^^^^^^^^^^^^^^^^^^^^ Thanks, This does the trick....
zeroes it out and stops the ls -a behaviour for the remainder of the session.
Should your script be in bash? It used, at least, to be practice to run a lot of shells as sh, and indeed if you change to sh you'll notice ls doesn't list dotfiles.
How about having a go with your script with sh as the shell? IIRC putting
#!/bin/sh
at the top of the file should do it.
HTH Fergus
On Thursday 24 November 2005 10:14, Chadley Wilson wrote:
On Thu, 2005-11-24 at 09:13 +0000, Fergus Wilde wrote:
On Thursday 24 November 2005 08:23, Chadley Wilson wrote:
Greetings,
Been struggling for a while trying to figure out why my script keeps removing the hidden directories:
When you run ls -l as a user you get a listing without the .xxxxx files, But as root ls -l shows all anyway.
So when root runs the script it deletes everything in the folder.
I assumed there was an alias runnng for ls but can't find it.
Can someone here please assist
Thanks Chadley
Now I look, the 'env' for a default user shows this variable set:
LS_OPTIONS=-N --color=tty -T 0
Whereas for root, 'env' shows:
LS_OPTIONS=-a -N --color=tty -T 0
So the 'ls -a' for root is coming from there. I'm just casting about trying to find out where that variable is set - first person to send a link to a thorough discussion of SuSE's bash variables gets a lollipop.
But you could perhaps put something in your script that unsets that part of the variable.
export LS_OPTIONS=
^^^^^^^^^^^^^^^^^^^^ Thanks, This does the trick....
Glad that worked: for completeness, AFAICT the environment variable $LS_OPTIONS is set from /etc/bash.bashrc on my SuSE 10 system, and it tests for uid 0 (i.e. probably root) and sets various things accordingly, including: <snippage> if test "$UID" = 0 ; then LS_OPTIONS="-a -N $LS_OPTIONS -T 0" else LS_OPTIONS="-N $LS_OPTIONS -T 0" fi </snippage> So if one wanted permanently to alter that behaviour for root, the advice from the top of /etc/bash.bashrc is: # PLEASE DO NOT CHANGE /etc/bash.bashrc There are chances that your changes # will be lost during system upgrades. Instead use /etc/bash.bashrc.local # for your local settings, favourite global aliases, VISUAL and EDITOR # variables, etc .. However if it were me I'd just do it for your script, in that if you are doing things with root privileges it strikes me as worthwhile to know about things like hidden files in the cwd. Best Fergus
On Thu, 2005-11-24 at 10:23 +0200, Chadley Wilson wrote:
Greetings,
Been struggling for a while trying to figure out why my script keeps removing the hidden directories:
When you run ls -l as a user you get a listing without the .xxxxx files, But as root ls -l shows all anyway.
You want to use ls -a (list all files including hidden files without attributes, files beginning with a dot are considered hidden), ls -l means long listing, show all attributes of the file but not hidden files. Check the aliases set for your login with aliases to see what is set for the ls command. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998
On Thursday 24 November 2005 14:10, Ken Schneider wrote:
On Thu, 2005-11-24 at 10:23 +0200, Chadley Wilson wrote:
Greetings,
Been struggling for a while trying to figure out why my script keeps removing the hidden directories:
When you run ls -l as a user you get a listing without the .xxxxx files, But as root ls -l shows all anyway.
You want to use ls -a (list all files including hidden files without attributes, files beginning with a dot are considered hidden), ls -l means long listing, show all attributes of the file but not hidden files. Check the aliases set for your login with aliases to see what is set for the ls command.
For most purposes you probably want -A instead of -a, since -A will exclude . and .. A related topic is dotglob (see man bash)
On Thu, 2005-11-24 at 20:27 +0100, Anders Johansson wrote:
On Thursday 24 November 2005 14:10, Ken Schneider wrote:
On Thu, 2005-11-24 at 10:23 +0200, Chadley Wilson wrote:
Greetings,
Been struggling for a while trying to figure out why my script keeps removing the hidden directories:
When you run ls -l as a user you get a listing without the .xxxxx files, But as root ls -l shows all anyway.
You want to use ls -a (list all files including hidden files without attributes, files beginning with a dot are considered hidden), ls -l means long listing, show all attributes of the file but not hidden files. Check the aliases set for your login with aliases to see what is set for the ls command.
For most purposes you probably want -A instead of -a, since -A will exclude . and ..
A related topic is dotglob (see man bash)
Thanks I read through it last night, I see the light.. :)
participants (4)
-
Anders Johansson
-
Chadley Wilson
-
Fergus Wilde
-
Ken Schneider