- To: slug <slug@xxxxxxxxxxx>
- Subject: [SLUG] useful bash tricks thread
- From: Tony Sceats <tony@xxxxxxxxxxx>
- Date: Fri, 6 Feb 2009 21:06:25 +1100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=DtjMHLM8o6Ww1ZDZYOiLPz1VRePgJ3O16TsSM4fI23U=; b=fs+wowTZilTAIERErKUETicYtqjJlaP/FDNjScuJ5enIEkfBquFml5ZZx6+M4nubzn YuuWrxbDODhQMHVckCDAr5bS/a8AJOs4T4gln9nmlrwTurFwAHxYA7I3/nEFcqVQJU7V h06tbDZJBKpPV52lqRxJ9pKwFwTVl5tI3F8lM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=agvPjc/M9hl4TIWeLm/53W7FO2axCld29ocGroBwNz8eiU5u7duGwJ42yL//95MHkB HmV0NB9Qg+ylEW7pBWpr1LjbiMj9CZ5nFdHsglgqIRbp5SNRK2F2d1BB6/5fpoOfOp1F RAz4+OpODtblBqgCW9Q6dEYc1B+WLUTshIQmQ=
It's been a while since there's been a thread like this, so I thought it
would be fun :)
so, have you got any?
I've got 2 to share today:
alt >and then
alt <
for interactive shells, works kinda like ctrl r or !$ - that is, it searches
your history but in a strangely useful but different way
-and-
built-in bash substitution, handy for decimal comparison (iff your decimal
precisions are the same)
tony@hermies:~$ VALUE=2.05
tony@hermies:~$ echo $VALUE
2.05
tony@hermies:~$ echo ${VALUE/./}
205
tony@hermies:~$ if [ ${VALUE/./} -gt 200 ] ; then echo $VALUE greater than
2;fi
2.05 greater than 2
and as you can see the substitution works for any chars, not just .
tony@hermies:~$ echo ${VALUE/2/4}
4.05
so there's no need to exec sed for simple stuff :)