It works for me, if the while loop reads from a text file.
What is pbpaste?
How does your input file look like? Is it Unix style? (where newline is LF, also the last line ends with LF, as opposed to DOS style where newline is CR LF and the last line has no newline)
pbpaste is an OSX command - copies from the clipboard to the terminal (stdin). I do not know if there is a direct UNIX/Linux equivalent, X11 xsel behaves the same.
pbpaste is a native command of MacOS (testing on a Mac at the moment). It pastes the contents you have in the clipboard.
If you have X, you can use this command instead
My input file is Unix style. I really don't know why this behavior is happening
EDIT: So I found out the script works correctly if the Description example has more than one line. However, if it's only one line, it doesn't. Is there any logic that I'm missing here?
Description field is not stored as a variable
Quote:
Your name: Test User
Email: test.usertestingthisstuff.com
Subject: Help
Description: Describe me in 2 words
Description field is stored as a variable successfully
Quote:
Your name: Rob King-Magee
Email: test.usertestingthisstuff.com
Subject: Help
Description: Describe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 wordsDescribe me in 2 words
Last edited by rbatte1; 04-25-2018 at 10:54 AM..
Reason: Added CODE tags
...
...
EDIT: So I found out the script works correctly if the Description example has more than one line. However, if it's only one line, it doesn't. Is there any logic that I'm missing here?
...
...
Upon searching about this topic in the Internet, I found that the "read" command may be unable to read a line that is not terminated by a newline.
However, I could not test it in my Cygwin Bash on Win 7 setup. If I create an input file that has your email input and remove "\n" from the end of the "Description" line, the script still works.
With "printf" though, I see that read fails if the "\n" is missing:
Could you confirm if the "pbpaste" command adds a newline at the end of the "Description" line?
For example, if you type "pbpaste" on the $ prompt of the Terminal, does the next prompt occur on its own line or right after the "Description" text?
If it is the latter, then the following code change might help:
(I don't have a Mac and don't have much idea about pbpaste - this is just a hunch.)
This User Gave Thanks to durden_tyler For This Post:
The following seems to work with bash on macOS High Sierra (version 10.13.4):
If you were using ksh instead of bash, the code suggested by durden_tyler in post #5 would also work.
This User Gave Thanks to Don Cragun For This Post:
Could you confirm if the "pbpaste" command adds a newline at the end of the "Description" line?
...
Hi durden_tyler,
The macOS pbpaste command writes whatever was last copied into the paste buffer. If the selected text included a trailing <newline>, a trailing <newline> will be included in the output; otherwise, there will not be a line-terminating <newline> for the last output partial line.
These 2 Users Gave Thanks to Don Cragun For This Post:
I am looking at a log file which just tells me the filename and the line number inside that file that has the Error. What I am interested is knowing the encapsulating function. For example, here are the contents of the log file
Error: foo.file on line wxy
Error: foo.file... (3 Replies)
Hello
I am using a grep command with two patterns in my KSH script. File has line breaks in it and both the patterns are in different lines. Here is the command grep -l 'RITE AID.*ST.820' natriter820u.20140914
Pattern1 - RITE AID
Pattern2 - ST*820
I am not getting any results from... (24 Replies)
I am using a grep command with two patterns in my KSH script. File has line breaks in it and both the patterns are in different lines. Here is the command - grep -l 'RITE AID.*ST.820' natriter820u.20140914
Pattern1 - RITE AID
Pattern2 - ST*820
I am not getting any results from this,... (3 Replies)
I am new to shell scripting and wished to get few things clarified.
While calling functions within shell script, output comes out as single line irrespective of the no of echos or newlines I tried within function +
the echo -e used to invoke function ( as instructed online) :
#!/bin/sh
inc() {... (1 Reply)
Here is the program I am trying to debug:
#include <stdio.h>
int i = 5;
int main(void)
{
int x = 3;
display(x);
return 0;
}
void display(int x)
{
for ( i=0; i<x; ++i ) {
printf("i is %d.\n", i);
}
}This code is coming from here Peter's gdb Tutorial: Stepping... (2 Replies)
I have a text file with file names, id like to have this portion of my BASH script go grab the line (which in this case is the full path to my file) then cat that file so I could pipe it to a email.
1) My text file (/tmp/1.txt) is setup like this:
... (3 Replies)
I need help with debugging an error in my awk script.
I have a shell script with variable named U_new_i and want to pass it to awk for use in a summation. The original file have the following content.
cat test.txt
-2445.7132000000
-2444.9349000000
-2444.3295000000
-2443.1814000000 ... (0 Replies)
I have no idea what the following means. The teacher is too advanced for me to understand fully. We literally went from running a few commands over the last few months to starting shell scripting. I am not a programmer, I am more hardware oriented. I wish I knew what this question was asking... (3 Replies)
I have this code, I thought it would automatically know the args sent to script when called from shell. But it seems to not see any...
main script:
. args
. errors
. opt
. clean
dbfile=""
opfile=""
# calls function in script below
chkarg
#check commands (2 Replies)
Hi,
I am new to AIX and I am developing a small tool for our product which helps debug memory leaks etc.
Q1)Is there a way in which i can get a function trace back as to the call (lets say malloc() )has been made in which file--> in which function.
I tried using the
#pragma options (... (0 Replies)