Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
HereStrings
Edit
PageHistory
Diff
Info
LikePages
!Here Strings A variant of [Here Documents|HereDocuments] the format is: *command <<< "string" A here string uses a form of I/O redirection to feed a command to an *interactive* program or a command, such as ftp, cat, ex or read. This can be extremely handy. So basically those apps you run that allow user input can be automatically fed strings rather than you typing them! I find Here Strings very useful to easily assign values to multiple variables. For Example: *IFS=: ; read foo bar moo <<< "yellow:red:blue"; Now try: *echo $foo $bar $moo and hopefully the value of the three variables will be displayed for you. !Read from a variable Make sure the variable is surrounded by *double* quotes! *string="this:is:a:string"; IFS=: ; read foo bar moo cow <<< "$string" *echo $foo $bar $moo $cow !Quick calculator <pre> bc <<<"2 + 2" 4 </pre> Note that, while bc(1) supports arbitrary precision, the default number of decimal points it displays is zero: <pre> bc <<<"3 / 2" 1 </pre> To change this, set the "scale" variable to the number of decimal places you want to see: <pre> bc <<<"scale = 3; 3 / 2" 1.500 </pre>
3 pages link to
HereStrings
:
HereDocuments
IORedirectionNotes
LawrenceDoliveiro