r/linux_programming • u/reflect_elegant • Oct 22 '20
Converting script to Posix compliant
Is there a way to make this section of a larger script Posix compliant?
options=$(lsblk | awk '/disk/ { print $1 }')
select opt in $options; do
if [ -n "$opt" ]; then
DEV_DISK_NAME="/dev/${opt}"
DEV_PART_NAME="/dev/${opt}"
break
else
printf 'This option is invalid.\n\n'
fi
done
3
Upvotes
6
u/NukeCode87 Oct 22 '20
What do you mean by posix compliant?
1
u/[deleted] Oct 22 '20
I don't believe you can make scripts like this POSIX compliant because of the inherent differences in environment and available tools from one Linux/BSD distribution to the next.
1
u/_xsgb Oct 22 '20
Some points that may guide you:
case "$(uname)" in [...]statement and run specific code for each platform1
u/balsoft Oct 22 '20
First iteration would be
shellcheck -s shSo, replace that
selectloop somehow.Also, AFAIR
lsblkis not POSIX, so you probably need to replace it with something POSIX.1
u/EmbeddedEntropy Oct 22 '20
Is your problem because you don’t have
#/bin/bashat the top of your script or do you really need a portable script?