RT 3.6.1 CLI--how to pass in a newline

Note: original question posted on the RT users list. This is a follow-up
and possible solution.

Thanks to der Mouse for the shell tutorial. :slight_smile:

I tried his suggestion and while I finally came to terms with my shell,
it confused the rt CLI. I was getting this with newlines:

rt: edit: No variables to set.

I messed around a bit and found that sticking the ‘xms’ at the end of
the regex seemed to make it work the way I wanted:

     elsif (/^set$/i) {
         my $vars = 0;

—> while (@ARGV && $ARGV[0] =~ /^($field)([±]?=)(.*)$/xms) {
my ($key, $op, $val) = ($1, $2, $3);

What I don’t know is if this causes other un-wanted side effects with
multi-line commands, thus my post to the dev list. Would this be a
desired or worthwhile patch?

Thanks,
Jim

der Mouse wrote:

So you’re thinking I need to trick the shell into sending the proper
newline character?

Yes, though I’m not sure “trick” is the best word. :slight_smile:

I use tcsh,

Try

% echo ‘foo
bar’

that is, a real newline, inside single quotes, but also backslashed.
That works in all csh derivatives I’ve run into, including a real tcsh
(6.13.00) I happen to have access to. (I don’t use tcsh myself.)

/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B

Jim Brandt
Administrative Computing Services
University at Buffalo

The patch was easy enough to generate, so it’s included below. It allows
you to pass in a string with newlines via ‘rt create’.

I was able to run all of lib/t/regression/26command_line.t with this in
place and it didn’t appear to break anything. I tried to create a few
new tests for this case, but it turned out to be difficult to pass a
command with a newline through Test::Expect.

It allows newlines for other fields as well, but it doesn’t seem to
break things. I tried with subject and RT seems to handle it correctly.
It does seem to retain the '' and put it at the end of the subject
string. Maybe it would be better to allow newlines only for fields that
allow them?

— bin/rt 2006-09-28 08:53:43.000000000 -0400
+++ /opt/rt3/bin/rt 2006-09-25 10:48:09.000000000 -0400
@@ -388,7 +388,7 @@
elsif (/^set$/i) {
my $vars = 0;

  •        while (@ARGV && $ARGV[0] =~ /^($field)([+-]?=)(.*)$/xms) {
    
  •        while (@ARGV && $ARGV[0] =~ /^($field)([+-]?=)(.*)$/) {
                my ($key, $op, $val) = ($1, $2, $3);
                my $hash = ($op eq '=') ? \%set : ($op =~ /^\+/) ? 
    

%add : %del;

Jim Brandt wrote:

Note: original question posted on the RT users list. This is a follow-up
and possible solution.

Thanks to der Mouse for the shell tutorial. :slight_smile:

I tried his suggestion and while I finally came to terms with my shell,
it confused the rt CLI. I was getting this with newlines:

rt: edit: No variables to set.

I messed around a bit and found that sticking the ‘xms’ at the end of
the regex seemed to make it work the way I wanted:

    elsif (/^set$/i) {
        my $vars = 0;

—> while (@ARGV && $ARGV[0] =~ /^($field)([±]?=)(.*)$/xms) {
my ($key, $op, $val) = ($1, $2, $3);

What I don’t know is if this causes other un-wanted side effects with
multi-line commands, thus my post to the dev list. Would this be a
desired or worthwhile patch?

Thanks,
Jim

der Mouse wrote:

So you’re thinking I need to trick the shell into sending the proper
newline character?

Yes, though I’m not sure “trick” is the best word. :slight_smile:

I use tcsh,

Try
% echo ‘foo
bar’

that is, a real newline, inside single quotes, but also backslashed.
That works in all csh derivatives I’ve run into, including a real tcsh
(6.13.00) I happen to have access to. (I don’t use tcsh myself.)

/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B

Jim Brandt
Administrative Computing Services
University at Buffalo

Is there any way to pass in a new line character via the CLI? I’m trying
to put one in the text field with ‘create’ and straight in with a ‘comment’.

An actual return confuses the shell, and everything else I tried is
translated literally. \n and
both just showed up that way in the
ticket. (It’s actually very cool that RT is translating everything
properly, but I’d like a control character to tell RT that I really want
a newline.)

Thanks,
Jim

Jim Brandt
Administrative Computing Services
University at Buffalo

Hi Jim,

We recently had an application that required us to import data containing newlines into our RT instance via the command-line tool. We found that the text field of the ‘create’ option does not accept newlines, however adding an actual newline character to a ‘comment’ does:

[root@support ~]# /opt/rt3/bin/rt comment -m 'foo

bar’ 40849
Password:
Message recorded
[root@support ~]# echo $?
0

Sincerely,
Frank Pater
DCANet

voice: 888-4-DCANET (888-432-2638)
fax: 302-426-6386On Thu, Aug 31, 2006 at 12:07:00PM -0400, Jim Brandt wrote:

Is there any way to pass in a new line character via the CLI? I’m trying
to put one in the text field with ‘create’ and straight in with a ‘comment’.

An actual return confuses the shell, and everything else I tried is
translated literally. \n and
both just showed up that way in the
ticket. (It’s actually very cool that RT is translating everything
properly, but I’d like a control character to tell RT that I really want
a newline.)

Thanks,
Jim


Jim Brandt
Administrative Computing Services
University at Buffalo


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Is there any way to pass in a new line character via the CLI? […]

An actual return confuses the shell,

This is a shell problem, then, and should be addressed as such. Every
shell I’ve used has a way to get a newline into a command argument -
though it’s not always easy to find. Which shell do you use?

/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B