Printf behavior on AIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printf behavior on AIX
# 1  
Old 05-22-2016
Printf behavior on AIX

command:

Code:
$ printf 'u1u1.%*s' 7

so if i run the above command on a linux box, i get the expected output of:

Code:
jserver@jserver-VirtualBox:~$ printf 'u1u1.%*s' 7
u1u1.       jserver@jserver-VirtualBox:~$ 
jserver@jserver-jserver:~$

it puts 7 spaces after the u1u1.

but when i run it on AIX or older systems, i get this:

Code:
$ printf 'u1u1.%*s' 7
printf: bad conversion
u1u1.s$

does anyone know of any command that will work across on UNIX platforms?
# 2  
Old 05-22-2016
There is no operand supplied for the %s conversion. Try:
Code:
$ printf 'u1u1.%*s' 7 ""

which should work with any printf utility.
# 3  
Old 05-22-2016
Quote:
Originally Posted by Don Cragun
There is no operand supplied for the %s conversion. Try:
Code:
$ printf 'u1u1.%*s' 7 ""

which should work with any printf utility.
i tried that. it didn't work:

Code:
$ printf 'u1u1.%*s' 7 ""
printf: bad conversion
printf: bad conversion
u1u1.su1u1.s$ 
$

# 4  
Old 05-22-2016
I apologize. The POSIX standards do specify the meaning of * in %*s in the printf family of functions (dprintf, fprintf, printf, snprintf, sprintf, fwprintf, swprintf, and wprintf) in the format string argument and in the awk printf and sprintf functions format string argument; but it does not specify the meaning of the * in %*s in the printf utility format string operand.

On OS X El Capitan (Version 10.11.5), the ksh and bash printf built-ins and the /usr/bin/printf stand-alone utility all produce the output:
Code:
u1u1.x       x

when invoked with the arguments:
Code:
printf 'u1u1.x%*sx\n' 7 ""

(which is what would be required by the C and awk printf functions when given those arguments).

Even though it isn't required by the standards, I'm surprised that the AIX printf utility doesn't implement it as a front-end to the C function. Do you get the same results with the stand-alone utility and the shell built-ins on AIX?
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 05-22-2016
printf
Quote:
No provision is made in this volume of POSIX.1-2008 which allows field widths and precisions to be specified as '*' since the '*' can be replaced directly in the format operand using shell variable substitution. Implementations can also provide this feature as an extension if they so choose.
Code:
width=7
printf "u1u1.%${width}s<" ""
u1u1.       <
printf "u1u1.%${width}s<" "xxx"
u1u1.    xxx<


Last edited by Aia; 05-22-2016 at 10:50 AM..
These 2 Users Gave Thanks to Aia For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need find package that supports printf on AIX

My current find command does not support printf. I need find package that supports printf on AiX 6.1 system. Can anyone help me with the download link or where / how / if I can find it ? Can it be installed at a different non default location so that it can be reference without... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. AIX

[ASK] - AIX Fibre Channel behavior

Hello all, Let me introduce about the context and my environment. We have an AIX 6.1 system, it has 4 FC channels / > lsdev -Cc adapter | grep fcs fcs0 Available 23-T1 Virtual Fibre Channel Client Adapter fcs1 Available 23-T1 Virtual Fibre Channel Client Adapter fcs2 Available 23-T1... (14 Replies)
Discussion started by: Phat
14 Replies

3. UNIX for Beginners Questions & Answers

awk Behavior

Linux Release Uname details Data file Ive been at the command line for some time. Back as far as SCO and Interactive Unix. I have always used this construct without issues. I want to isolate the ip / field 1. As you can see .. the first line is "skipped". This works as... (6 Replies)
Discussion started by: sumguy
6 Replies

4. AIX

LUN Behavior

Aix 6.1, working with a nim master and nim_altmaster both LPARS have access to the same data LUN, /nimdisk I do realize the risks of having 2 servers access the same LUN, however it serves the purpose of being able to restore mksysb's to/from our DR site if necessary, at least in theory ;) ... (3 Replies)
Discussion started by: mshilling
3 Replies

5. Programming

Strange behavior in C++

I have the following program: int main(int argc, char** argv){ unsigned long int mean=0; for(int i=1;i<10;i++){ mean+=poisson(12); cout<<mean<<endl; } cout<<"Sum of poisson: "<< mean; return 0; } when I run it, I get the... (4 Replies)
Discussion started by: santiagorf
4 Replies

6. AIX

Different behavior of LC_COLLATE in AIX & LINUX

1. I have created following files in both AIX & Linux touch a A b B c C x X y Y z Z 2. In AIX $ LC_COLLATE=en_US ; export LC_COLLATE $echo $ a b c x y z 3. In LINUX $ LC_COLLATE=en_US ; export LC_COLLATE $ echo $ a A b B c C x X y Y z Could anyone please explain the... (5 Replies)
Discussion started by: Anu_1
5 Replies

7. Solaris

Unexpected df behavior

Hi, I have Sun SPARC Enterprise T5140 with two 2,5" 15rpm 146GB SAS HDD. In friday there were a lot of errors with fs on them. After reconfiguring all seemed to be fine but today I get the following strange behavior of df -kh command and troubles with files, I written on first disk in friday.... (9 Replies)
Discussion started by: Sapfeer
9 Replies

8. Shell Programming and Scripting

Echo behavior

Echo is removing extra blank spaces. See the command. export INSTALLDIR=”First Second /Two Space” echo $INSTALLDIR out put: First Second /Two Space Here only on blnak space is present while with command Echo “$INSTALLDIR” Out put: ”First Second /Two Space” It's correct output... (2 Replies)
Discussion started by: Saurabh78
2 Replies

9. Programming

ls behavior

I put this here because it is a 'behavior' type question.. I seem to remember doing ls .* and getting all the .-files, like .profile .login etc. But ls .* doesn't do that, it lsts the contents of every .*-type subdirectory. Is it supposed to? I should think that a -R should be given to... (10 Replies)
Discussion started by: AtleRamsli
10 Replies
Login or Register to Ask a Question