gpart add -t freebsd-ufs -s 1G da0 | cut -d ' ' -f 1
export PART=`gpart add -t freebsd-ufs -s 1G da0 | cut -d ' ' -f 1`
echo $PART
Is that a bash only or does it work for old fashioned "sh" too?Whenever there are simple white-space separated fields to parse, I just use set and avoid the pipe (processes are expensive):
Bash:set -- $(gpart add -t freebsd-ufs -s 1G da0) PART=$1 FROB=$5 FOOBAR="$7 $8 $9"
It's plain old Bourne shell. The "code" language selection box does not have "sh", only "bash", which I think is a serious forum SW omission. It uses theIs that a bash only or does it work for old fashioned "sh" too?
set
built-in, where set foo bar baz
sets $1 to foo, $2 to bar and $3 to baz.[...] I actually wanted to get the partition number into a variable.
# PARTNO=$(echo 'da3p312 added' | sed 's/.*p\(.*\)\ added/\1/')
# echo $PARTNO
312
What's still unclear?Thanks to schweikh I have a means getting the partition number of new partition into a variable...
Code:set -- $(gpart add -t freebsd-ufs -s 1G da0) PART=$1
Not sure that I totally understand it though. At least I learnt something new.
$()
is the POSIX way for command substitution (backticks don't nest easily). And set
is the way to set the shell's positional parameters $1, $2, ... from its arguments.Whenever there are simple white-space separated fields to parse, I just use set and avoid the pipe (processes are expensive; plain /bin/sh code):
sh:set -- $(gpart add -t freebsd-ufs -s 1G da0) PART=$1 FROB=$5 FOOBAR="$7 $8 $9"
#!/bin/sh
mount -t ext2fs /dev/ada0p1 /mnt
tar xf /mnt/mfsbsd-se-13.2-RELEASE-amd64.iso -C /media
umount /mnt
set -- $(gpart add -t freebsd-ufs -s 10G -l FreeBSD-test da0)
PART=$1
newfs /dev/$PART
mount /dev/$PART /mnt
tar zxf 13.2-RELEASE-amd64/base.txz -C /mnt
tar zxf 13.2-RELEASE-amd64/kernel.txz -C /mnt
+ mount -t ext2fs /dev/ada0p1 /mnt
+ tar xf /mnt/mfsbsd-se-13.2-RELEASE-amd64.iso -C /media
+ umount /mnt
+ gpart add -t freebsd-ufs -s 10G -l FreeBSD-test da0
gpart: Invalid argument
+ set --
+ PART=''
+ newfs /dev/
newfs: /dev/: could not open special device
+ mount /dev/ /mnt
mount: /dev: Block device required
+ tar zxf 13.2-RELEASE-amd64/base.txz -C /mnt
tar: Error opening archive: Failed to open '13.2-RELEASE-amd64/base.txz'
+ tar zxf 13.2-RELEASE-amd64/kernel.txz -C /mnt
tar: Error opening archive: Failed to open '13.2-RELEASE-amd64/kernel.txz'
What happens when you remove "-l FreeBSD-test"? You do have a da0 device, right? And it has room for another 10G?+ gpart add -t freebsd-ufs -s 10G -l FreeBSD-test da0
gpart: Invalid argument
The problem was that da0 used an MBR scheme so thatWhat happens when you remove "-l FreeBSD-test"? You do have a da0 device, right? And it has room for another 10G?
gpart add -t freebsd-ufs
failed.