![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HP-UX recycle | Hemanth_gp | UNIX for Dummies Questions & Answers | 3 | 07-02-2008 05:28 PM |
| Making UNIX script executable | rohitx | UNIX for Dummies Questions & Answers | 4 | 07-01-2008 01:32 PM |
| Path of Recycle Bin on Windows | milhan | Windows & DOS: Issues & Discussions | 4 | 01-19-2007 03:31 PM |
| Recycle Bin Script | raidersboi | UNIX for Dummies Questions & Answers | 6 | 06-04-2005 11:32 PM |
| error making filesystem when install UNIX | jav_v | Filesystems, Disks and Memory | 3 | 08-28-2002 10:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hello, I'm only taking Intro to UNIX in school right now, so please bear with me. My problem is with a sort-of recycle-bin rig I've created for fun. I'm using Ubuntu 9.04, I am the admin. (only user, actually) of this computer. I'm using this script in ~/.bashrc
Code:
# if files exist, remove contents (of purge directory) ls -lA ~/purge; echo "^ this was a test, to be sure the following command should work" purgeTest= "ls -lA ~/purge" # setting a variable to check contents of ~/purge if [ $purgeTest -ne "total 0" ]; then rm -r ~/purge/* fi Here is the output I'm seeing on login: Code:
total 0 ^ this was a test, to be sure the following command should work bash: ls -lA ~/purge: No such file or directory bash: [: -ne: unary operator expected jzacsh@dell8300:~$ what am i doing wrong to get the "no such file or directory" error, in line 3 just above? (am I using variables incorrectly?) is -ne operator only for mathematic comparisons - line 4 of error? if so, what should I use? -thanks in advance for any suggestions! |
|
||||
|
pludi: thanks for the quick reply. I actually wrote this originally for my Intro to Unix class, where I needed somewhere to stick temporary files I was working on/looking at, that I didn't want to worry about remembering to clean up. In that class we use FreeBSD. I fixed the errors you mentioned, thank you for the advice.
This is what my code looks like now: Code:
# if files exist, remove contents of purge directory purgeTest=`ls -lA ~/purge` if [$purgeTest!="total 0"]; then rm -r ~/purge/* fi Code:
bash: [total: command not found |
|
||||
|
Awesome, that worked! (I guess I got rid of the unnecessary whitespace and the necessary). Thanks.
I'm glad you mentioned that, I'm actually a bit confused with the different files. My UNIX teacher taught us ~/.profile was what you use, then the ubuntu forums explained you should use .bashrc for an assignment (like the one I did below). Code:
alias test="cd $HOME/prog/test ; pwd ; ls -la" |
|
||||
|
Different shells, more likely. Nothing but BASH uses .bashrc . Lots of linux systems use BASH, but lots of other UNIX systems generally login to ksh or others. Though I have seen situations where a read-only .bashrc exists to prevent people mucking with it, that automatically includes .profile or somesuch if present.
Last edited by Corona688; 04-27-2009 at 08:30 PM.. |
|
|||||
|
According to the man page of bash the sequence is
Furthermore, bash will run ~/.bash_logout whenever a login shell exits, and ~/.bashrc when running an interactive non-login shell. |
![]() |
| Bookmarks |
| Tags |
| operators, scripting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|