Score:0

bash error !{P: event not found

cn flag

What is wrong with this command sequence:

stephen@stephen:~$ RETENTION=3
stephen@stephen:~$ echo $RETENTION
3
stephen@stephen:~$ SNAP=bpool/BOOT/ubuntu_7pdn8o@autozsys_
stephen@stephen:~$ sudo zfs list -t snapshot -o name | grep ^$SNAP | sed -n -e :a -e "1,${RETENTION}!{P;N;D;};N;ba" | xargs -n 1 echo zfs destroy -nprd
bash: !{P: event not found

?

The intent here is to delete all but the three most recent snapshots. What should be there instead of !{P to accomplish this?

Score:3
hr flag

Double quotes allow bash to treat ! as a shell history event designator. If you want to prevent that, but still allow expansion of shell variable ${RETENTION}, you can switch from double quotes to single quotes after the variable:

"1,${RETENTION}"'!{P;N;D;};N;ba'
Stephen avatar
cn flag
This worked. Thanks :)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.