LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-18-2015, 04:36 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
Is there a way that the Bash recognizes hex numbers in command lines?


Is there a way that the Bash recognizes hex numbers in command lines? Take for instance 'dd if=file1 of=file2 bs=1 skip=0x1BE'.
 
Old 01-18-2015, 05:37 AM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
dd if=file1 of=file2 bs=1 skip=$(echo $((0x1BE)))

You could have found the answer yourself just googling for:

bash hex to decimal conversion

as that's what I did.

PS Maybe the command in your example works as is, but then it's a feature of dd, not of bash. Did you try?

Last edited by Didier Spaier; 01-18-2015 at 05:58 AM. Reason: PS added.
 
Old 01-18-2015, 06:24 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Yes I did. About your finding, much more straightforward translate to base ten with my pocket calculator but thanks anyways. Indeed I looked into the bash man page. There are some references to hex base but none of them seemed to apply. By the way, LQ is not an oracle. Nor is it a developer's mailing list. It's just LQ [smiling face].
 
Old 01-18-2015, 06:38 AM   #4
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
As far as the Shell Command Language is in concern, the primary source of information is not bash's manual but the Shell & Utilities volume of The Open Group Base Specifications Issue 7 aka the POSIX specification, of which bash is an implementation, plus extensions. Reading the specification it is clear that '0x1BE' is just a token for the shell, and that to interpret it as an hexadecimal number you need to submit it to an arithmetic expansion.

Last edited by Didier Spaier; 01-18-2015 at 06:47 AM.
 
Old 01-18-2015, 06:53 AM   #5
rg3
Member
 
Registered: Jul 2007
Distribution: Fedora
Posts: 527

Rep: Reputation: Disabled
Minor note: the echo is not needed. dd if=file1 of=file2 bs=1 skip=$(( 0x1BE )) should work.
 
2 members found this post helpful.
Old 01-18-2015, 06:56 AM   #6
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by rg3 View Post
Minor note: the echo is not needed. dd if=file1 of=file2 bs=1 skip=$(( 0x1BE )) should work.
That's right, thanks for the heads up. I am used to complicate things uselessly

Oh and printf could be used also, as specified in POSIX, in our case the bash builtin command version of printf.

Last edited by Didier Spaier; 01-18-2015 at 06:59 AM.
 
Old 01-18-2015, 06:59 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Which is paradoxical I think, because hex (or rather binary but it's almos the same thing) is the numeric system the machine understands.
 
Old 01-18-2015, 07:03 AM   #8
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by stf92 View Post
Which is paradoxical I think, because hex (or rather binary but it's almos the same thing) is the numeric system the machine understands.
  1. bash is not an assembler
  2. so you've got a machine that understands? Lucky man
 
Old 01-18-2015, 07:21 AM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by Didier Spaier View Post
  1. bash is not an assembler
  2. so you've got a machine that understands? Lucky man
'bash is not an assembler': bash is the bulkiest language I've seen in my life. I the SEE ALSO section of the man page there are mentioned sh (1) and csh (1), but neither sh nor its man page are anywhere to be seen. Maybe in the first releases of slack there is one.
 
Old 01-18-2015, 08:04 AM   #10
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by stf92 View Post
'bash is not an assembler': bash is the bulkiest language I've seen in my life. I the SEE ALSO section of the man page there are mentioned sh (1) and csh (1), but neither sh nor its man page are anywhere to be seen. Maybe in the first releases of slack there is one.
If you don't like bash, you may use another shell.

Type this:
Code:
ls -l /bin|grep sh$
You will see that actually Slackware ships no less than five shells, each whith its own man page.

Want more? You can get dash, the C shell from bsd or the MidnightBSD Korn Shell at no additional cost.

Last edited by Didier Spaier; 01-18-2015 at 08:06 AM.
 
Old 01-18-2015, 09:47 AM   #11
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Since I'm in a nit-picky mood, the OP's statement...
Quote:
...but neither sh nor its man page are anywhere to be seen.
...is true as written.

There's no man page for sh and there is no Bourne shell executable; there's a link to bash which is compatible.
 
1 members found this post helpful.
Old 01-18-2015, 10:55 AM   #12
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Anyone uses what one wants and can get. Personally, I tend to stay POSIX compliant as much as possible and avoid extensions if that doesn't lead to something way too convoluted. That doesn't prevent me to use bash, but not all features of it. I am far to know all its features anyway but don't care.

Last edited by Didier Spaier; 01-18-2015 at 10:58 AM.
 
Old 01-18-2015, 11:00 AM   #13
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
OK, now: Is sh, the Bourne shell, too old for slackware 14.0?
 
Old 01-18-2015, 11:29 AM   #14
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by stf92 View Post
OK, now: Is sh, the Bourne shell, too old for slackware 14.0?
I don't know it it can be compiled on Slackware 14.0, but you could try this version (for Unix V7. That's the only one I was able to find).

EDIT. Actually, there's also this one. but I don't know if it differs from the genuine one, neither in what respect.

PS You might also want to have a look at this discussion. If I can trust what is said there, there can be two reasons for which the Bourne Shell or one of its close derivatives is not shipped in "Unix like" OS:
  • A license issue
  • That it be not POSIX compliant.
But at it seems logical that a POSIX compliant shell can be found from /bin/sh, this is usually a link to another shell (bash in Slackware's case).

Last edited by Didier Spaier; 01-18-2015 at 11:47 AM. Reason: PS added.
 
1 members found this post helpful.
Old 01-18-2015, 11:46 AM   #15
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
From a newbie to a veteran: is one expected to download all of those files one at a time?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to convert hex numbers to assemble codes? Henry1989 Programming 4 12-17-2012 07:51 AM
[SOLVED] How to use sed command to delete lines only 1-3 digit numbers on a particular column? kahthiam Linux - Newbie 4 12-27-2011 07:41 AM
In Python, printing leading zero for hex numbers 0 through f donpar Programming 1 04-15-2009 07:09 PM
Bash command to list installed libraries and version numbers newtovanilla Linux - Newbie 4 07-18-2008 04:49 PM
Bash script: add all numbers from command output wi-Z-art Programming 2 08-06-2003 09:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration