LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Trying to find meaning of command with ½ (https://www.linuxquestions.org/questions/slackware-14/trying-to-find-meaning-of-command-with-%C2%BD-4175477698/)

waddles 09-19-2013 03:37 AM

Trying to find meaning of command with ½
 
I do not recognize what the command line with ???? means.
Can someone explain it to me.
Code:

OUT=`curl -m 2 --range 0-0 $URL 2> /dev/null|while read -n 1 C
do
  OUT="${OUT}½"  # ????
  echo $OUT
  [ ${#OUT} -gt 1 ] && break
done`


Keith Hedger 09-19-2013 05:43 AM

This is an odd character and is not a command either the file is corrupt or you are using the wrong encoding try using 'cat' on the file as it usually gets the encoding right.

allend 09-19-2013 07:13 AM

The way I read that code fragment is that the variable OUT gets 0xC20xBD appended if there is a file available at $URL.
Are we trying to hack our Nikes? Apparently those two bytes are used to specify a device address for a nRF24L01 ultra low power RF transceiver.
http://dmitry.gr/index.php?r=05.Proj...%20plus%20iPod
http://stackoverflow.com/questions/2...an-i-access-it

waddles 09-19-2013 08:24 AM

This is from a curl file splitting script:
http://splitcurl.googlecode.com/git/splitcurl
Those 2 characters appear there and when viewed with cat/vi.
This part of the script is testing for "splitness" which may be how evenly they are split??
Since the output is dumped to null and times out after 2 seconds and is examining the 1st byte, appending those characters to whatever is in COPY would guarantee the length ${#OUT} is greater than 1, regardless, wouldn't it?
Such logic if I have followed it correctly seems superfluous. Please correct me if I have done an injustice to the coder.

Keith Hedger 09-19-2013 09:07 AM

Quote:

Originally Posted by waddles (Post 5030693)
...appending those characters to whatever is in COPY would guarantee the length ${#OUT} is greater than 1, regardless, wouldn't it?...

You could be right ( sorry should have looked at the whole code not just the odd character ), its common to add a character to a string in bash so that you don't get null string errors ie
Code:

if [ X${SOMESTRING} = "X" ];then
echo "String is empty or null but doesn't generate an error
fi

The two 'X's cancel out.

So the coder MAY have just tacked this character on to the end of the string in which case the string would be greater than one if curl had downloaded something and have a length of 1 if not, personally I would do a check for an empty/null string but that's just personal preference.

Try replacing the odd character with say 'X' and run the script if it behaves as it should then that is the reason for the odd character.

waddles 09-19-2013 03:28 PM

Don't feel sorry Keith, initially I saw that as a string manipulation- dah!
I will be attempting to take UR advise.


All times are GMT -5. The time now is 10:37 PM.