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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
06-11-2017, 03:44 AM
|
#16
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,223
|
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.
|
06-12-2017, 12:46 PM
|
#17
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep: 
|
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
Last edited by L_Carver; 06-12-2017 at 12:48 PM.
|
|
|
06-12-2017, 04:20 PM
|
#18
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,814
|
Quote:
Originally Posted by L_Carver
...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).
|
|
|
06-16-2017, 12:47 PM
|
#19
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep: 
|
Quote:
Originally Posted by ntubski
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
Last edited by L_Carver; 06-16-2017 at 12:52 PM.
Reason: Changed some phrasing.
|
|
|
06-16-2017, 12:56 PM
|
#20
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,223
|
Quote:
Originally Posted by L_Carver
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
|
|
|
06-16-2017, 01:04 PM
|
#21
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,886
|
Quote:
Originally Posted by L_Carver
Code:
[[ -f "dummy" ]] && rm -f dummy
|
Wouldn't just 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.
|
|
|
06-16-2017, 01:20 PM
|
#22
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,815
|
Quote:
Originally Posted by L_Carver
As for going with single quotes on the 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.
|
|
|
06-16-2017, 02:24 PM
|
#23
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,814
|
Quote:
Originally Posted by L_Carver
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 tell you? I guess the file you are editing is not the same as the file you are running.
|
|
|
06-17-2017, 07:54 AM
|
#24
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep: 
|
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
|
|
|
06-17-2017, 08:33 AM
|
#25
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep: 
|
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
|
|
|
06-17-2017, 10:30 AM
|
#26
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,223
|
Quote:
Originally Posted by L_Carver
...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.
|
|
|
06-18-2017, 03:39 AM
|
#27
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep: 
|
Quote:
Originally Posted by pan64
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 auto date, 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, auto touch. 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.
|
|
|
06-18-2017, 05:44 AM
|
#28
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,223
|
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)
|
|
|
06-18-2017, 11:15 AM
|
#29
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep: 
|
What color is the egg on my face now?
Quote:
Originally Posted by pan64
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 OR 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.
|
|
|
06-18-2017, 02:38 PM
|
#30
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.5
Posts: 5,886
|
Quote:
Originally Posted by L_Carver
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
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.
|
|
|
All times are GMT -5. The time now is 06:21 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|