Issue with CD to a hidden dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with CD to a hidden dir
# 1  
Old 06-11-2010
Question Issue with CD to a hidden dir

I have written a script to secure delete all files in a quarantine folder and my Trash folder. All the commands run trough Terminal via the script.
The problem I am having is when I am changing the directory to the hidden Trash folder. When I do
Code:
cd /Users/WatsonN/.Trash

all it does is take it to the /Users/WatsonN folder instead. The problem with this is that the next command is
Code:
srm -rfdv *

, so it starts with /Users/WatsonN/Desktop and works its way down. Luckily i caught it before it destroyed anything important.

here is the entire script:
Code:
#! /bin/sh
# 
# Nathan Watson
# Nathan@WatsonN.com
#
clear
#Logo
cat /art.txt
#END Logo
#echo Let's start this bad boy on up!!
echo Movin' it on over to Quarantine
cd /Users/WatsonN/Desktop/Quarantine
echo CHModdin them files...
chmod +rw *
echo Here we go.............
srm -rfv *
echo DONE!!!!! YAY!!!!!!!!!!
#
#
echo Now lets tear up that trash can!
echo Lookie here the trash bin....
cd /Users/WatsonN/.Trash
echo Gittin' that trash out of my trailer..... 
srm -rfdv *
echo There ain't no trash in my trailer no more.....

echo CHECK FILES ARE GONE...
cd /Users/WatsonN/Desktop/Quarantine  #LINE 28
echo LISTING........
echo .....Quarantine.....
ls -a
#
echo .....Trash.....
cd /Users/WatsonN/.Trash
ls -a
echo DONE

another issue is this
Quote:
./srm: line 28: unexpected EOF while looking for matching `''
./srm: line 42: syntax error: unexpected end of file
Line 42 is the line after everything that is after
Code:
echo DONE


Thank you so much in advanced Smilie
# 2  
Old 06-11-2010
Try to escape the single quotes in the echo arguments:

Code:
echo Gittin\' that trash out of my trailer.....

Code:
echo There ain\'t no trash in my trailer no more.....

You should check the exit status of the cd command:

Code:
cd /Users/WatsonN/.Trash || {
  printf 'Error accessing %s\n' '/Users/WatsonN/.Trash'
  exit 1
  }

This User Gave Thanks to radoulov For This Post:
# 3  
Old 06-11-2010
MySQL

Thank you so much Smilie
It was the single quotes. I ALWAYS forget some little detail. What can I say Its not my job, I dont have to know it Smilie

Thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsync - how to copy hidden folder or hidden files when using full path

Hello. I use this command : rsync -av --include=".*" --dry-run "$A_FULL_PATH_S" "$A_FULL_PATH_D"The data comes from the output of a find command. And no full source directories are in use, only some files. Source example... (2 Replies)
Discussion started by: jcdole
2 Replies

2. UNIX for Beginners Questions & Answers

Finding Files with Perl on a Hidden Dir?

Greetings! Been a while since I futzed around with Perl, and came upon a minor headscratcher for the community ;) Here's the basic code which I'm trying to make tick over:#!/usr/bin/perl use strict; use warnings; use diagnostics; print " starting "; while (-e "~/.somedir/testFile")... (9 Replies)
Discussion started by: LinQ
9 Replies

3. Shell Programming and Scripting

Issue with copying files into dir inside for loop

Hi , I'm trying to move/copy the files inside the loop into a directory . I tried the below code and the issue is the data is not copying into the created directory but the files are copying into another file file_path="/home/etc" Last_Day=20130930 mkdir $file_path/ARC_${Last_Day} ... (3 Replies)
Discussion started by: smile689
3 Replies

4. Shell Programming and Scripting

Access Issue - dir and script

Hi All, I got access in UNIX box from our client. I am able to create folder, files, script etc.. in that folder. here is the issue: my login/base folder is = /home/ace I have created 2 folders within it Script ScriptLog in Script folder i have created 2 .ksh file ... (1 Reply)
Discussion started by: ace_friends22
1 Replies

5. UNIX for Dummies Questions & Answers

List all directories hidden or not hidden

I want to list all directories hidden or not hidden. ls -ld */ => shows only not hidden directories so i guess the answer would be to add the a option to show all files ls -lad */ => not working :confused: ls -la | grep "^d" => works But I would like to know why I can't use ls -lad... (4 Replies)
Discussion started by: servus
4 Replies

6. Cybersecurity

Inquiry of .awo hidden dir with bin file inside .eeesync extension

Hi, Me i ask if someone knows about this hidden directory or it me knows where this dir associated with or in a program. I had and notices this .awo dir with bin files inside title 6770669_info.eeesync files in my directory. I wonder if this is associated with my backup program or any program... (0 Replies)
Discussion started by: jao_madn
0 Replies

7. Solaris

home dir mount issue

Hi all, I have to mount my home directory in one box, by default everyone's home directory will mount in all unix boxes which we have. But we have unmounted these home directories from some boxes to keep the data as safe. So for automation purpose i need my home directory only in those boxes to... (2 Replies)
Discussion started by: raghu.iv85
2 Replies

8. Shell Programming and Scripting

Finding Hidden files and protecting the folder containing hidden files from deletion

Hi. I have a script which is deleting files with a particular extension and older than 45 days.The code is: find <path> -name "<filename_pattern>" -mtime +45 -exec rm {} \; But the problem is that some important files are also getting deleted.To prevent this I have decide to make a dummy... (4 Replies)
Discussion started by: pochaw
4 Replies

9. Solaris

NFS file/dir disappear issue

We have bunch of Sun Sparc workstations(solaris 7 & 8) connecting to a linux file server with NFS exports. Recently we upgraded our file server from fedora core1 to redhat enterprise linux 4. And since then we are experiencing a nightmare of file/dir missing. It happens randomly, couple of times... (1 Reply)
Discussion started by: motor98
1 Replies
Login or Register to Ask a Question