[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

See 8chan's new software in development (discuss) (help out)
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


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

4b1284 No.3527

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]

4b1284 No.3528

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}


e37647 No.3586

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.


4a2cb5 No.3588

>>3527

>>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][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]