[ / / / / / / / / / ] [ dir / ask / dcaco / fur / hypno / o / sl / ttgg / u ][Options][ watchlist ]

/prog/ - Programming

Programming board

Catalog

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): 1446662895001.png (518.36 KB, 800x873, 800:873, 5pvZoue.png) (h) (u)

[–]

e48c91 (2) No.3527>>3588 [Watch Thread][Show All Posts]

why is there no prog help sticky?

i guess this question will become a noob scripting help general so i won't feel bad for mucking up this board.

i'm trying to crate a script for my zsh prompt to display my laptop's battery in different colors depending on how full it is.

I need to isolate the percentage without the '%' and sometimes a ',' to do the math.

[CODE]

#!/bin/bash

ACPI=$(acpi)

BATTERY=$(echo $ACPI | gawk '{ print $4 }')

STATE=$(echo $ACPI | gawk '{ print $3 }')

STATE=${STATE:0:1}

if [[ ${BATTERY:${#BATTERY}} -ne '\%' ]]

then

echo "hello"

fi

if [[ $STATE -eq "U" ]]

then

STATE=F

fi

echo $STATE:$BATTERY

#${BATTERY:0:${#BATTERY}-2}

[/CODE]

e48c91 (2) No.3528>>3588

oops


#!/bin/bash
ACPI=$(acpi)
BATTERY=$(echo $ACPI | gawk '{ print $4 }')
STATE=$(echo $ACPI | gawk '{ print $3 }')

STATE=${STATE:0:1}

if [[ ${BATTERY:${#BATTERY}} -ne '\%' ]]
then
STATE=${BATTERY:0:${#BATTERY}-2}
fi

if [[ $STATE -eq "U" ]]
then
STATE=F
fi

echo $STATE:$BATTERY
#${BATTERY:0:${#BATTERY}-2}


865cb0 (1) No.3586>>3588

I also need help with a Java error /prog/

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0

at java.lang.String.charAt(String.java:658)

at Project4.main(Project4.java:19)

here is the area in my driver program

System.out.println("--------Shipping Menu---------"+("\nO: Overnight")+("\nP: Priority")+("\nS: Standard Shipping"));
newCo.setShippingCode(kb.nextLine().charAt(0));

what can I do to fix this error.


d255d3 (1) No.3588

>>3527 (OP)

>>3528

You really need to give us more to go on. Most of us will not have an "acpi" command on hand. Show us the input to your script and tell us exactly what is going wrong. You haven't even told us what is not working.

An immediate issue I can see is that you're using echo $ACPI, where it should be echo "$ACPI". Not quoting it takes each individual part as an argument to echo, and destroys all formatting and whitespace.

>>3586

Not enough information. Whatever kb.nextLine() is grabbing from, kb.nextLine() ends up with a 0-length string. Check the size of the string before indexing into it in this case, or wrap it in a try so you can catch the exception.

Read this:

http://sscce.org/




[Return][Go to top][Catalog][Screencap][Update] ( Scroll to new posts) ( Auto) 5
3 replies | 0 images | 3 UIDs | Page ?
[Post a Reply]
[ / / / / / / / / / ] [ dir / ask / dcaco / fur / hypno / o / sl / ttgg / u ][ watchlist ]