LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-11-2017, 03:44 AM   #16
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,641

Rep: Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615

set -xv is not error checking, but debugging. That means the shell will print a lot of information about what's happening. But that will not check anything for you. Instead, you need to check yourself if the program flow is what you expected or not.
Again you did not post what you really tried therefore noone will tell you what's wrong with that.

Additionally if you post an output produced using set -xv we can go through to understand line by line.

Last edited by pan64; 06-11-2017 at 01:03 PM.
 
1 members found this post helpful.
Old 06-12-2017, 12:46 PM   #17
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
Question Current script is attached; output of ...

...running the script with set -xv (line 2) and ls dummy (right after) looks like:
Code:
farragut/public $ autotouch $picc
The empty file, dummy, is now dated as follows
2013-12-18 05:18:06.000000000 -0500
farragut/public $ ls dummy
dummy
The command in the script to remove dummy is now
Code:
[[ -f "dummy" ]] && rm -f dummy
You have what I have. Now where can I go?

Carver
Attached Files
File Type: txt autotouch.txt (311 Bytes, 11 views)

Last edited by L_Carver; 06-12-2017 at 12:48 PM.
 
Old 06-12-2017, 04:20 PM   #18
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,605

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Quote:
Originally Posted by L_Carver View Post
...running the script with set -xv (line 2) and ls dummy (right after) looks like:
Here's what it looks like for me:
Code:
$ ./autotouch.sh words.txt
SAVEIFS=$IFS
+ SAVEIFS='
'
IFS=$"\n\b"
+ IFS='\n\b'

picc=$1
+ picc=words.txt
if [ -f "$picc" ]; then
    if [ ! -z "$TDATE" ]; then
        touch dummy
        touch -t "$TDATE" dummy
        echo "The empty file, dummy, was dated as follows"
        stat -c %y dummy
        touch -r "dummy" "$picc"
        [[ -f "dummy" ]] && rm -f dummy
    fi
    /home/steve/bin/nodummy
    IFS=$SAVEIFS
./autotouch.sh: line 18: syntax error: unexpected end of file
Quote:
You have what I have. Now where can I go?
Try to work out the difference between what you posted and what you actually ran (also, we don't have /home/steve/bin/nodummy).
 
Old 06-16-2017, 12:47 PM   #19
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
Try to work out the difference between what you posted and what you actually ran (also, we don't have /home/steve/bin/nodummy).
Sorry. I thought I'd either pasted "nodummy" in or uploaded it. Solving that (non)problem now. As the uploaded version shows, it's just "hashbang, check that dummy exists, if so remove it, if not say so" as a separate script. Basically I don't see why I can't do the remove-it part in "autotouch" (the longer, parent script), and that's the modification I'm having trouble with.

And I did not get the error you did when you ran "autotouch." I must have fixed it after posting and thus the non-working version was prone to err out. Here's the (error-free) version of the script as it ran today:
Code:
#!/bin/bash
set -xv
SAVEIFS=$IFS
IFS=$'\n\b'

picc=$1
if [ -f "$picc" ]; then
if [ ! -z "$TDATE" ]; then
 touch dummy
 touch -t "$TDATE" dummy
 echo "The empty file, dummy, was dated as follows"
 stat -c %y dummy
 touch -r "dummy" "$picc"
[[ -f "dummy" ]] && rm -f dummy
fi
/home/steve/bin/nodummy
IFS=$SAVEIFS
What I can't explain is that the 'set -xv' doesn't return any of the executed commands to stdout. And that was what i "reported" in my post of the 10th @ 6:05 AM.

Carver
Attached Files
File Type: txt nodummy.txt (91 Bytes, 9 views)

Last edited by L_Carver; 06-16-2017 at 12:52 PM. Reason: Changed some phrasing.
 
Old 06-16-2017, 12:56 PM   #20
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,641

Rep: Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615
Quote:
Originally Posted by L_Carver View Post
What I can't explain is that the 'set -xv' doesn't return any of the executed commands to stdout. And that was what i "reported" in my post of the 10th @ 6:05 AM.

Carver
I would rather say those commands were really not executed. By the way set -xv sends its output to stderr, not stdout.

Last edited by pan64; 06-16-2017 at 01:13 PM. Reason: typo
 
Old 06-16-2017, 01:04 PM   #21
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,442

Rep: Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070
Quote:
Originally Posted by L_Carver View Post
Code:
[[ -f "dummy" ]] && rm -f dummy
Wouldn't just
Code:
rm -f dummy
work? You shouldn't need to test for the presence of the file dummy when using rm -f [force]. The force will suppress any error reporting -- you won't get a "No such file or directory" from rm.
Code:
[scasey:~]$ rm dummy
rm: cannot lstat `dummy': No such file or directory
[scasey:~]$ rm -f dummy
[scasey:~]$
Please try that and let us know.
 
Old 06-16-2017, 01:20 PM   #22
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,555

Rep: Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088
Quote:
Originally Posted by L_Carver View Post
As for going with single quotes on the
Code:
IFS=$"\n\b"
I may try that, too. Double-quotes with me are reflections of my Cygwin days, and I usually "break" a bash install with them (as with mv and renaming single files) by using them.
You had better learn to do it right or you will have no end of trouble. The two are very different, especially when the quoted string is preceded by "$".

From the bash manpage:
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.
and
A double-quoted string preceded by a dollar sign ($"string") will cause the string to be translated according to the current locale. If the current locale is C or POSIX, the dollar sign is ignored.
Presumably, the first is what you wanted, though <newline> and <backspace> are a rather odd combination for field separators.
 
Old 06-16-2017, 02:24 PM   #23
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,605

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Quote:
Originally Posted by L_Carver View Post
And I did not get the error you did when you ran "autotouch." I must have fixed it after posting and thus the non-working version was prone to err out. Here's the (error-free) version of the script as it ran today:
Code:
#!/bin/bash
set -xv
SAVEIFS=$IFS
IFS=$'\n\b'

picc=$1
if [ -f "$picc" ]; then
if [ ! -z "$TDATE" ]; then
 touch dummy
 touch -t "$TDATE" dummy
 echo "The empty file, dummy, was dated as follows"
 stat -c %y dummy
 touch -r "dummy" "$picc"
[[ -f "dummy" ]] && rm -f dummy
fi
/home/steve/bin/nodummy
IFS=$SAVEIFS
Nope, that still has the same error: there are 2 if and only 1 fi.

Quote:
What I can't explain is that the 'set -xv' doesn't return any of the executed commands to stdout. And that was what i "reported" in my post of the 10th @ 6:05 AM.
What does
Code:
which autotouch
tell you? I guess the file you are editing is not the same as the file you are running.
 
Old 06-17-2017, 07:54 AM   #24
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
Following latest advice...

...I made these changes to the body of the script (leave off, for the moment, my IFS declaration.):
Code:
rm -f dummy
fi
else
 echo -e "The file $picc is not in this directory.\nHas it been moved?"
fi
# Just in case that bit hiccups again:
/home/steve/bin/nodummy
IFS=$SAVEIFS
And per the double-quote around "/n/b," I had it happen while editing another script that changing " to ' resulted in an unmatched " kind of error, so I changed them back.

Carver

Last edited by L_Carver; 06-17-2017 at 07:55 AM. Reason: Thought of a better Subject: line
 
Old 06-17-2017, 08:33 AM   #25
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
Unhappy single quotes '/n/b' work, but...

...the commands to delete dummy are still ignored, as is, it appears, the set -xv command.
I copied the script with the name 'autodate,' and set -xv works fine in it.

Carver
 
Old 06-17-2017, 10:30 AM   #26
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,641

Rep: Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615
Quote:
Originally Posted by L_Carver View Post
...the commands to delete dummy are still ignored
Carver
You need to understand, the program will do what is implemented, not what you wish. Commands cannot be ignored, there is no such feature and there is no similar bug in bash. The only thing I can imagine the program flow is simply different: it either stopped before - or run on another branch (if/then/else).
set -xv works always, if used, that will not influence the program flow anyway but print the lines as they executed.

You need to check if there was any error message.
 
Old 06-18-2017, 03:39 AM   #27
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
You need to understand, the program will do what is implemented, not what you wish. Commands cannot be ignored, there is no such feature and there is no similar bug in bash. The only thing I can imagine the program flow is simply different: it either stopped before - or run on another branch (if/then/else).
set -xv works always, if used, that will not influence the program flow anyway but print the lines as they executed.

You need to check if there was any error message.
There are no error messages. I see the script executing step-by-step when I run autodate, the copy of the working script (as I should with set -xv on line 4), but I do not see it execute step-by-step in the original script, autotouch. After running autodate, I've noticed from recent runs, the modified date of the file it was supposed to touch with the value in tdate does not change, but dummy is still deleted. When I run autotouch, the mod date changes but dummy isn't deleted (the issue for the second half of this thread). a-date not changing the date of the target file is bad; a-touch leaving dummy behind (and on top of that, neither checking if there is a dummy file nor executing nodummy) is also bad.

Each script has one or two parts that "don't work," and I've been trying to figure out why.

I'm trying to remove the 'old' file dummy in anticipation of situations where I may want to change the mod date of a file but noclobber IS set. I would like to set it on my own system at some
point and still have this/these script/s work. If there's a 'touch' command that creates a new file dummy every time either the first or second script is executed, that won't fly.

Carver

Last edited by L_Carver; 06-18-2017 at 03:41 AM.
 
Old 06-18-2017, 05:44 AM   #28
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,641

Rep: Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615Reputation: 5615
so it looks like you execute different files (not the one you posted), execute something with different names or in different directories and checks something, but you never tell us what was really executed, what's happened exactly and what was expected. Please post exactly the full script you executed, the full output generated (exactly) and do not try to cut/explain modify them, just post as it is.
Otherwise it looks completely pointless (at least for me)
 
Old 06-18-2017, 11:15 AM   #29
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
Thumbs down What color is the egg on my face now?

Quote:
Originally Posted by pan64 View Post
so it looks like you execute different files (not the one you posted), execute something with different names or in different directories and checks something, but you never tell us what was really executed, what's happened exactly and what was expected. Please post exactly the full script you executed, the full output generated (exactly) and do not try to cut/explain modify them, just post as it is.
Otherwise it looks completely pointless (at least for me)
What is expected is: the script will "touch" the target file with the -t type string value in the variable tdate, then delete the dummy file it creates to pass this along to. I read earlier in this thread or the earlier thread (on trimming down the code for this script) that one of the better ways to pass a modification date to a new file with a script was to create a dummy file and then copy its modification date to the "new" file.

The ways I execute (consistently from the time I wrote the first version of this script to the date I'm writing this reply) have either been
Code:
 autotouch $picc
OR
Code:
 autotouch foo.jpg
Now I've discovered that the script files are not the problem. It turns out I wrote the commands of the original autotouch into a function in my .bash_aliases file, which looks like this:
Code:
function autotouch () {

if [[ -f dummy ]]; then rm dummy; fi
if [ ! -z "$tdate" ]; then
touch dummy
 touch -t "$tdate" dummy
 echo "The empty file, dummy, is now dated as follows"
 stat -c %y dummy
 touch -r "dummy" "$picc"
fi
[[ -f dummy ]]; rm dummy
}
And coincidentally, when executed, the "rm dummy" does not remove the dummy file.

Carver

Last edited by L_Carver; 06-18-2017 at 11:16 AM. Reason: "either been either" is bad American; corrected.
 
Old 06-18-2017, 02:38 PM   #30
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,442

Rep: Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070
Quote:
Originally Posted by L_Carver View Post
If there's a 'touch' command that creates a new file dummy every time either the first or second script is executed, that won't fly.
touch will always create a new file if the filename doesn't exist when it is run. So the first command below is unnecessary (but won't hurt anything)
Code:
touch dummy
 touch -t "$tdate" dummy
Quote:
Originally Posted by pan64 View Post
so it looks like you execute different files (not the one you posted), execute something with different names or in different directories and checks something, but you never tell us what was really executed, what's happened exactly and what was expected. Please post exactly the full script you executed, the full output generated (exactly) and do not try to cut/explain modify them, just post as it is.
Otherwise it looks completely pointless (at least for me)
What pan64 said. Emphasis is mine.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
googleearth Suddenly Has Stopped Working HaroldWho Slackware 2 10-21-2014 08:48 PM
Touchscreen suddenly stopped working Fa773N_M0nK Linux - Laptop and Netbook 2 12-20-2012 02:56 AM
Printer stopped working suddenly? NightSky Slackware 11 12-26-2008 04:50 AM
vmware suddenly stopped working leupi Linux - Software 7 01-22-2007 08:47 PM
airsnort suddenly stopped working fatrandy13 Linux - Security 1 09-23-2004 08:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration