sh

How to perform bitwise operations on hexadecimal numbers in bash?

孤街浪徒 提交于 2019-11-30 11:13:22
In my bash script I have a string containing a hexadecimal number, e.g. hex="0x12345678" . Is it possible to treat it as a hex number and do bit shifting on it? You can easily bitshift such numbers in an arithmetic context: $ hex="0x12345678" $ result=$((hex << 1)) $ printf "Result in hex notation: 0x%x\n" "$result" 0x2468acf0 Of course you can do bitwise operations (inside an Arithmetic Expansion): $ echo "$((0x12345678 << 1))" 610839792 Or: $ echo "$(( 16#12345678 << 1 ))" 610839792 The value could be set in a variable as well: $ var=0x12345678 # or var=16#12345678 $ echo "$(( var << 1 ))"

Explanation of convertor of cidr to netmask in linux shell netmask2cdir and cdir2netmask [closed]

半城伤御伤魂 提交于 2019-11-30 10:42:37
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I found the following shell functions from this topic mask2cdr () { # Assumes there's no "255." after a non-255 byte in the mask local x=${1##*255.} set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*} x=${1%%$3*} echo $(( $2 + (${#x}/4) )) } cdr2mask () { #

Select unique or distinct values from a list in UNIX shell script

*爱你&永不变心* 提交于 2019-11-30 10:04:47
问题 I have a ksh script that returns a long list of values, newline separated, and I want to see only the unique/distinct values. It is possible to do this? For example, say my output is file suffixes in a directory: tar gz java gz java tar class class I want to see a list like: tar gz java class 回答1: You might want to look at the uniq and sort applications. ./yourscript.ksh | sort | uniq (FYI, yes, the sort is necessary in this command line, uniq only strips duplicate lines that are immediately

Perl: Shebang (space?) “#! ”?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 08:02:11
问题 I've seen both: #!/path/... #! /path/... What's right? Does it matter? Is there a history? I've heard that an ancient version of Unix required there not be a space. But then I heard that was just a rumor. Does anyone know for certain? Edit: I couldn't think where better to ask this. It is programming related, since the space could make the program operate in a different way, for all I know. Thus I asked it here. 回答1: I also have a vague memory that whitespace was not allowed in some old Unix

What does “$?” give us exactly in a shell script? [duplicate]

只愿长相守 提交于 2019-11-30 07:59:48
This question already has an answer here: Meaning of $? (dollar question mark) in shell scripts 8 answers I saw the code written somewhere online, and I wanted to know what exactly does "$?" do/give us. Googling did not help. Here's the code I saw it in: #!/bin/sh ping -c 2 localhost if [ $? != 0 ] ; then echo "Couldn't ping localhost, weird" fi ping -c 2 veryweirdhostname.noend if [ $? != 0 ] ; then echo "Surprise, Couldn't ping a very weird hostname.." fi echo "The pid of this process is $$" Taken from: http://efod.se/writings/linuxbook/html/shell-scripts.html $? is a variable holding the

Problems installing Java EE SDK on Linux

懵懂的女人 提交于 2019-11-30 06:21:23
I installed the Java 6 JRE on my VPS just fine, but I can't get the EE SDK installation to even run. root@vps [/usr/java]# java -version java version "1.6.0_18" Java(TM) SE Runtime Environment (build 1.6.0_18-b07) Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode) However, when I try to run java_ee_sdk-6-unix.sh : ./ ../ java_ee_sdk-6-unix.sh* jre1.6.0_18/ jre.bin* root@vps [/usr/java]# ./java_ee_sdk-6-unix.sh Could not locate a suitable jar utility. Please ensure that you have Java 6 or newer installed on your system and accessible in your PATH or by setting JAVA_HOME But the catch is

Argument list too long - Unix

情到浓时终转凉″ 提交于 2019-11-30 06:01:10
问题 This scripts will sort the files by date then move the first 2500 files to another directory. When I run below scripts, system prompt out Argument list too long msg. Anyone can help me enhance the scripts ? Thanks NUM_OF_FILES=2500 FROM_DIRECTORY=/apps/data01/RAID/RC/MD/IN_MSC/ERC/in DESTINATION_DIRECTORY=/apps/data01/RAID/RC/MD/IN_MSC/ERC/in_load if [ ! -d $DESTINATION_DIRECTORY ] then echo "unused_file directory does not exist!" mkdir $DESTINATION_DIRECTORY echo "$DESTINATION_DIRECTORY

Bourne Shell For i in (seq)

半腔热情 提交于 2019-11-30 05:13:28
I want to write a loop in Bourne shell which iterates a specific set of numbers. Normally I would use seq : for i in `seq 1 10 15 20` #do stuff loop But seemingly on this Solaris box seq does not exist. Can anyone help by providing another solution to iterating a list of numbers? try for i in 1 10 15 20 do echo "do something with $i" done else if you have recent Solaris, there is bash 3 at least. for example this give range from 1 to 10 and 15 to 20 for i in {1..10} {15..20} do echo "$i" done OR use tool like nawk for i in `nawk 'BEGIN{ for(i=1;i<=10;i++) print i}'` do echo $i done OR even the

perl backticks: use bash instead of sh

心已入冬 提交于 2019-11-30 05:03:34
问题 I noticed that when I use backticks in perl the commands are executed using sh, not bash, giving me some problems. How can I change that behavior so perl will use bash? PS. The command that I'm trying to run is: paste filename <(cut -d \" \" -f 2 filename2 | grep -v mean) >> filename3 回答1: Try `bash -c \"your command with args\"` I am fairly sure the argument of -c is interpreted the way bash interprets its command line. The trick is to protect it from sh - that's what quotes are for. 回答2: