Skip to main content

All Questions

Tagged with
1 vote
2 answers
98 views

Why does printf fail with "invalid number" within bash script but not at command line? [closed]

I have this function in a bash script: ver_to_num() { printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' ') } ver_to_num 3.18.1.1 works from the command line. But when used in a ...
erikor's user avatar
  • 386
0 votes
1 answer
67 views

How do I use the printf command with a format string beginning with "-"? [duplicate]

I have some items: items=(one two three) And I want to print them with leading -, to give this output: - one - two - three The obvious format string fails: printf '- %s\n' "${items[@]}" ...
Toby Speight's user avatar
  • 31.4k
0 votes
4 answers
102 views

Create string based on array values

I am trying to create a tree structure like the tree command. To keep track of the "heirarchy", I have an array like ("true" "true" "false") or ("true&...
moys's user avatar
  • 8,085
1 vote
1 answer
119 views

printf format specifier %h; is it standard?

Commands printf 'ABC$def%hx\n' 10 # output: ABC$defa printf 'ABC$def%s\n' 10 # output: ABC$def10 work as expected.... but I cannot find any info about %h. Is it available on all systems?
Antonio Rizzo's user avatar
1 vote
1 answer
69 views

Printing array with printf vs echo gives different results [duplicate]

I am trying to create an array from a file. In the troubleshooting process, I hope to print out all elements of the array to convince myself I'm doing it correctly. However, when I use a hard coded ...
coyk's user avatar
  • 11
0 votes
1 answer
68 views

Bash printf format for Eszett (scharfes S, sharp s) takes up 2 positions

I want to use printf under bash to format german verbs as follows: INFINITIV PRATERITUM PERFEKT 3.PERS. SING heißen hieß hat geheißen er heißt kaufen ...
pwp's user avatar
  • 161
1 vote
1 answer
89 views

printf() is too slow in bash

I was trying to output numbers in hex with bash. The code below finishes in roughly 150 milliseconds: count=0 for a in {0..15999}; do ((count++)) output=$a if (( count == 15 )); then echo -...
raijin's user avatar
  • 198
0 votes
1 answer
149 views

Is there an equivalent of Bash shell printf %q in C?

Bash shell built-in function printf has the format specifier %q that will: > quote the argument in a way that can be reused as shell input Example (Bash shell): printf '%q' "abc\ndef" .....
kevinarpe's user avatar
  • 21.4k
1 vote
1 answer
132 views

bash printf broken for floats

I have a bash script that gets battery information. Here's part of it: #!/bin/bash if [ -f /sys/class/power_supply/BAT0/energy_full ]; then EF=$( echo $(cat /sys/class/power_supply/BAT0/energy_full)...
JFBonzo's user avatar
  • 13
0 votes
2 answers
110 views

Bash: Conditional formatting against an array with printf

In a bash script, I have some dynamic entries in an array that assemble together at one point for readable output with printf. I'd like to save the cursor at some point while printing through the ...
algalg's user avatar
  • 821
2 votes
3 answers
159 views

how i can print or sum one larger hex in bash

when i use printf "%064X\n" $((0x1a838b13505b26867)) the number one was truncated 000000000000000000000000000000000000000000000000A838B13505B26867 with big hex/number is worse printf "...
Sasori's user avatar
  • 23
0 votes
1 answer
62 views

Bash Command Substitution in echo/printf doesn't print result on the same line? [duplicate]

Reproducible example Consider this example: #!/usr/bin/env bash echo "[Status] $(killall --wait example)" Expected output: [Status] example: no process found Actual result (being wrong ...
GrabbenD's user avatar
  • 530
0 votes
1 answer
61 views

The newline (\n) is not working in END block in bash [duplicate]

I need to define the "\n" in END block as it will be passed to other bash script as an argument. I have added an empty newline at the begin and at the end. But only the begin empty line (\n) ...
stackbiz's user avatar
  • 1,468
0 votes
1 answer
132 views

How to print echo command's output and a function's output side by side in same line?

I am trying to output a diamond shape with the following bash script. #!/bin/bash read -p "Please write a number: " number # Printing asterisks according to input: for i in $(seq 1 "$...
Oguzhan's user avatar
0 votes
1 answer
37 views

command in bash contains printf but the format is not hand over to variable [duplicate]

Bashversion: 4.2.46 OS: linux 3.10.0-1160.108.1.e17 the following command with with printf shall provide three columns with 10 Characters. Running this only in bash all works fine. $ free -h | grep ...
falcon68's user avatar

15 30 50 per page
1
2 3 4 5
32
X