@@ -24,6 +24,7 @@ static usec_t arg_timeout = DEFAULT_TIMEOUT_USEC;
2424static bool arg_multiple = false;
2525static bool arg_no_output = false;
2626static AskPasswordFlags arg_flags = ASK_PASSWORD_PUSH_CACHE ;
27+ static bool arg_newline = true;
2728
2829STATIC_DESTRUCTOR_REGISTER (arg_message , freep );
2930
@@ -54,6 +55,8 @@ static int help(void) {
5455 " --accept-cached Accept cached passwords\n"
5556 " --multiple List multiple passwords if available\n"
5657 " --no-output Do not print password to standard output\n"
58+ " -n Do not suffix password written to standard output with\n"
59+ " newline\n"
5760 "\nSee the %2$s for details.\n" ,
5861 program_invocation_short_name ,
5962 link ,
@@ -104,7 +107,7 @@ static int parse_argv(int argc, char *argv[]) {
104107
105108 /* Note the asymmetry: the long option --echo= allows an optional argument, the short option does
106109 * not. */
107- while ((c = getopt_long (argc , argv , "+he " , options , NULL )) >= 0 )
110+ while ((c = getopt_long (argc , argv , "+hen " , options , NULL )) >= 0 )
108111
109112 switch (c ) {
110113
@@ -177,6 +180,10 @@ static int parse_argv(int argc, char *argv[]) {
177180 arg_credential_name = optarg ;
178181 break ;
179182
183+ case 'n' :
184+ arg_newline = false;
185+ break ;
186+
180187 case '?' :
181188 return - EINVAL ;
182189
@@ -237,8 +244,14 @@ static int run(int argc, char *argv[]) {
237244 return log_error_errno (r , "Failed to query password: %m" );
238245
239246 STRV_FOREACH (p , l ) {
240- if (!arg_no_output )
241- puts (* p );
247+ if (!arg_no_output ) {
248+ if (arg_newline )
249+ puts (* p );
250+ else
251+ fputs (* p , stdout );
252+ }
253+
254+ fflush (stdout );
242255
243256 if (!arg_multiple )
244257 break ;
0 commit comments