[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#17637: bug "cut of end-line is skipped"
From: |
Eric Blake |
Subject: |
bug#17637: bug "cut of end-line is skipped" |
Date: |
Thu, 29 May 2014 16:15:21 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
On 05/29/2014 03:43 PM, rd wrote:
> helo, i'm a bash shell script beginner...
> forgive my poor English, i'd like to contribute to GNU O.S. reporting
> this suspect bug.
>
> it was working perfectly the command from
> ubuntu 12.04 LTS after installed "at" using the terminal command apt-get
> install at
>
> #################################
> echo "`atq`" |cut -d$'\n' -f1 | cut -d$'\t' -f1
Useless use of echo of a command substitution. Also, cutting by newline
delimiters is unusual, and tab is already the default field delimiter,
so isn't that the same as the much more idiomatic expression:
atq | head -n1 | cut -f1
> ##################################
> #! /bin/sh
You are claiming to have a sh script (rather than a /bin/bash script)...
> #
> Kill_All_Jobs()
> {
> local Job_Pid=""
...yet you are using bashisms that are not portable to POSIX sh. Are
you sure that your problems are not being caused by Ubuntu's use of dash
as it's /bin/sh?
> echo "`atq`" |cut -d$'\n' -f1 | cut -d$'\t' -f1
> #################################
> give to a different output result!
> example output is
>
> 94234
> 94356
> 94237
It's better if you can boil your problem report into something
independent of atq. But it does indeed look like we broke something;
here's comparing the cut on Fedora 20 vs. the latest coreutils.git:
$ printf 'a\t1\nb\t2\nc\t3\n' | cut -d$'\n' -f1
a 1
$ cut --version | head -n1
cut (GNU coreutils) 8.21
$ git describe
v8.22-107-ge431477
$ printf 'a\t1\nb\t2\nc\t3\n' | src/cut -d$'\n' -f1
a 1
b 2
c 3
Although I see entries in the NEWS file for cut fixes in coreutils 8.21,
I don't see anything mentioned since then that would explain this change
in behavior. I'll do a git bisect to see if I find a culprit.
> so i'd like to have reply from the follow questions:
> 1- what is the correct syntax to use cut with atq command to extract the
> job id?
What you have works, but is fragile if atq ever switches to using space
instead of tab delimiters (for field extraction, I prefer awk over cut,
as it is more powerful and still fairly concise).
> 2- the output from shell commands use the same field separator and line
> separator?
Not sure what you are asking here.
> 3- there is a standar output format or metod from shell commands?
Individual utilities might have a specified format ('atq' is a non-POSIX
extension, but appears to be a common alias for the 'at -l' command
which POSIX requires to use tab delimiters:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/at.html
). But in general, a lot of utilities use ad-hoc output format styles,
and shell scripting just has to deal with it.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature