I'm trying to get this shell script to work in make:
$ VERSION=$(echo 'ThisBuild / version := "1.20"' | grep -e 'This.*version' | grep -Eo '[0-9]+\.[0-9]+')
$ echo $VERSION
1.20
make:
$ make -v
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Makefile:
version:
VERSION=$(echo 'ThisBuild / version := "1.20"' | grep -e 'This.*version' | grep -Eo '[0-9]+\.[0-9]+') && \
echo "VERSION: ${VERSION}"
Doesn't work:
$ make version
VERSION= && \
echo "VERSION: "
VERSION:
Can this be done?
If you want to pass $ to the shell you have to escape it from make, by doubling it: $$.
version:
VERSION=$$(echo 'ThisBuild / version := "1.20"' | grep -e 'This.*version' | grep -Eo '[0-9]+\.[0-9]+') && \
echo "VERSION: $${VERSION}"
Otherwise, make will think that you're referencing a make variable and expand it.
Related
Running a nx affected:apps command gives me this output:
> NX NOTE Affected criteria defaulted to --base=master --head=HEAD
> NX Affected apps:
- app-backend
- app-frontend
- app-something
- app-anything
I need to get all the application names and use them again for a command call.
So I started with that
output=$(nx affected:apps)
echo "$output" | grep -E "^\W+app-(\w+)"
This gives me
- app-backend
- app-frontend
- app-something
- app-anything
But I need to get the names only instead to run foo --name={appname} four times.
Also not quite sure how to use it in a loop. Quite new to bash scripting :-(
You may use -o (show matches only) with -P (perl regex moode) in gnu-grep:
nx affected:apps |
grep -oP "^\W+app-\K\w+" |
xargs -I {} docker build -t {} .
If gnu-grep isn't available then use this awk command:
nx affected:apps |
awk -F- '/app-/{print $3}' |
xargs -I {} docker build -t {} .
I don't have nx command here but you can try using xargs:
nx affected:apps | grep '^ -' | cut -d' ' -f4 | xargs -I{} echo docker build -t {} ./dist/{}
Remove echo to actually run the command.
You can use the --plain option:
nx affected:apps --plain
the command should return all the affected apps with space as a divider. You can then store those to a bash array and cycle through them in a for loop, running the command you need:
#!/bin/bash
AFFECTED=($(./node_modules/.bin/nx affected:apps --plain))
for t in ${AFFECTED[#]}; do
echo $t
done
My below script is not giving the correct java version from the remote server, instead prints the version of the source server:
for i in 'cat serverlist.txt'
do
ssh $i `java -version 2>&1 >/dev/null | grep 'java version' | awk '{print $3}'|sed 's/"//g'`
done >>sample.txt
cat sample.txt
expected result would like below:
eg: 1.8.181 (each server would be having a different version, that shud be printed)
You shouldn't be using back ticks in remote command - single quotes are probably what you're looking for:
ssh $i 'java -version 2>&1 >/dev/null | grep "version" | cut -d" " -f 3-'
I am able to get my results correctly after trying the below:
ssh $server >sample.txt 2>&1 java -version 2>&1 >/dev/null | grep 'java version' | awk '{print $3}'|sed 's/"//g' >>s1.txt exit; cat s1.txt
I want to compare two Debian systems with respect to packages version numbers. For that I need a file listing of all installed packages like this:
a2ps 1:4.14-1.3
abiword 3.0.0-8+b1
acl 0.6.37-3+b1
...
I wrote a bash script (rather clumsy) that collects the required info, but I cannot make it write to a file. Can someone help me to fix this?
dpkg --get-selections \
| grep "\binstall\b" \
| sed 's/\(^[A-Za-z0-9\.\-\_]*\).*/\1/' \
| while read i ; \
do `echo $i` `apt-cache policy $i \
| grep Install \
| sed 's/ *Installed: *\([A-Za-z0-9\.\-\_]*\)/\1/' `\
; done
Thank you.
dpkg-query --show -f '${Package}\t${Version}\n' > out.txt
Is there a way to get golang version from pkg/ or from compiled binary?
I want to automate removal of $GOPATH/pkg folder only when I change the golang version.
Nevermind, found the answer
[ `strings $pkg_a_file | grep 'go object' | head -n 1 | cut -f 5 -d ' '` != `go version | cut -f 3 -d ' '` ] && \
rm -rf $GOPATH/pkg
strings $pkg_a_file | grep 'go object' | head -n 1 | cut -f 5 -d ' ' part will show something like go1.6.2
pkg_a_file can be something like this:
PKG_OS_ARCH=`go version | cut -d ' ' -f 4 | tr '/' '_'`
pkg_a_file=$GOPATH/pkg/$PKG_OS_ARCH/gitlab.com/kokizzu/gokil/A.a
External reference: http://kokizzu.blogspot.co.id/2016/06/solution-for-golang-slow-compile.html
With 1.9.2, the grep command is
strings $pkg_a_file | grep 'Go cmd/compile'
I found the following method, to check the version of Go lib used to compile the binary
$ strings compiled_binary | grep '^go1'
go1.17.4
I got this curious problem with Alpine. I want to check the checksum of a file inside a bash console. It works under CentOS but not under Alpine. Where is the error?
Under CentOS
$ sha1sum /bin/tini
fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini
$ echo "fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini" | sha1sum -c -
/bin/tini: OK
Under Alpine
$ sha1sum /bin/tini
fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini
$ echo "fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini" | sha1sum -c -
sha1sum: WARNING: 1 of 1 computed checksums did NOT match
Could you try adding 1 space (total 2) between the checksum and the path:
$ echo "fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini" | sha1sum -c -
I've tried with /bin/busybox:
# sha1sum /bin/busybox
71bdaf6e52759f7f277c89b694c494f472ca2dfb /bin/busybox
# echo '71bdaf6e52759f7f277c89b694c494f472ca2dfb /bin/busybox' | sha1sum -c -
sha1sum: WARNING: 1 of 1 computed checksums did NOT match
# echo '71bdaf6e52759f7f277c89b694c494f472ca2dfb /bin/busybox' | sha1sum -c -
/bin/busybox: OK
The error is because sha1sum expects its own output as input when called with -c and its output uses 2 spaces.
I had this issue while installing kubectl on Alpine Linux v3.13:
echo "$(<kubectl.sha256) kubectl" | sha256sum -c
sha256sum: WARNING: 1 of 1 computed checksums did NOT match
My two-part fix:
the default shell (ash) responds to echo "$(<file.txt)" with an empty new line whereas bash responds with the contents of the file (expected behavior).
Alpine's version of sha256sum wants two spaces between the hash and the file name (Ubuntu accepts one space).
bash
echo "$(<kubectl.sha256) kubectl" | sha256sum -c
kubectl: OK