| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright (c) 2006-2008 John Goerzen, jgoerzen@complete.org This module provides shell-like commands. Most, but not all, are designed to be used directly as part of a HSH pipeline. All may be used outside HSH entirely as well. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Synopsis | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Documentation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
abspath :: FilePath -> IO FilePath | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Return the absolute path of the arg. Raises an error if the computation is impossible. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
appendTo :: FilePath -> String -> IO String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Like catTo, but appends to the file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
basename :: FilePath -> FilePath | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The filename part of a path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bracketCD :: FilePath -> IO a -> IO a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Changes the current working directory to the given path, executes the given I/O action, then changes back to the original directory, even if the I/O action raised an exception. This is an alias for the MissingH function System.Path.bracketCWD. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catFrom :: [FilePath] -> String -> IO String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Load the specified files and display them, one at a time. The special file - means to display the input. If it is not given, no input is processed (though a small amount may be read into a buffer). Unlike the shell cat, - may be given twice. However, if it is, you will be forcing Haskell to buffer the input. Note: buffering behavior here is untested. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catFromBS :: [FilePath] -> ByteString -> IO ByteString | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lazy ByteString version of catFrom. This may have performance benefits. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catBytes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catBytesFrom | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catTo :: FilePath -> String -> IO String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Takes input, writes it to the specified file, and does not pass it on. The return value is the empty string. See also catToBS, catToFIFO, tee. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catToBS :: FilePath -> ByteString -> IO ByteString | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Like catTo, but operates in a lazy ByteString. This could be a performance benefit. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catToFIFO :: FilePath -> String -> IO String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Like catTo, but opens the destination in ReadWriteMode instead of ReadOnlyMode. Due to an oddity of the Haskell IO system, this is required when writing to a named pipe (FIFO) even if you will never read from it. This call will BLOCK all threads on open until a reader connects. This is provided in addition to catTo because you may want to cat to something that you do not have permission to read from. See also catTo, catToFIFOBS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
catToFIFOBS :: FilePath -> ByteString -> IO ByteString | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Like catToFIFO, but for lazy ByteStrings | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd :: FilePath -> IO () | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
An alias for System.Directory.setCurrentDirectory. Want to change to a user's home directory? Try this: glob "~jgoerzen" >>= cd . head See also bracketCD. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cut :: Integer -> Char -> String -> String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Split a list by a given character and select the nth list. cut ' ' 2 "foo bar baz quux" -> "bar" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cutR :: [Integer] -> Char -> String -> String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Split a list by a given character and select ranges of the resultant lists. cutR [2..4] ' ' "foo bar baz quux foobar" -> "baz quux foobar" cutR [1..1000] ' ' "foo bar baz quux foobar" -> "bar baz quux foobar" cutR [-1000..1000] ' ' "foo bar baz quux foobar" -> "foo bar baz quux foobar" Note that too large and too small indices are essentially ignored. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dirname :: FilePath -> FilePath | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The directory part of a path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
discard :: Handle -> Handle -> IO () | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Read all input and produce no output. Discards input completely. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo :: String -> () -> String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Takes a string and sends it on as standard output. The input to this function is never read. See also echoBS. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echoBS :: ByteString -> () -> ByteString | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ByteString.Lazy version of echo. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
exit :: Int -> IO a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Exits with the specified error code. 0 indicates no error. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
glob :: FilePath -> IO [FilePath] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Takes a pattern. Returns a list of names that match that pattern. Handles: ~username at beginning of file to expand to user's home dir ? matches exactly one character * matches zero or more characters [list] matches any character in list [!list] matches any character not in list The result of a tilde expansion on a nonexistant username is to do no tilde expansion. The tilde with no username equates to the current user. Non-tilde expansion is done by the MissingH module System.Path.Glob. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
grep :: String -> [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Search for the string in the lines. Return those that match. Same as: grep needle = filter (isInfixOf needle) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
grepV :: String -> [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Search for the string in the lines. Return those that do NOT match. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
egrep :: String -> [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Search for the regexp in the lines. Return those that match. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
egrepV :: String -> [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Search for the regexp in the lines. Return those that do NOT match. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
joinLines :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Join lines of a file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lower :: String -> String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert a string to all upper or lower case | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
upper :: String -> String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mkdir :: FilePath -> FileMode -> IO () | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Creates the given directory. A value of 0o755 for mode would be typical. An alias for System.Posix.Directory.createDirectory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
numberLines :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Number each line of a file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pwd :: IO FilePath | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
An alias for System.Directory.getCurrentDirectory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readlink :: FilePath -> IO FilePath | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Return the destination that the given symlink points to. An alias for System.Posix.Files.readSymbolicLink | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
readlinkabs :: FilePath -> IO FilePath | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
As readlink, but turns the result into an absolute path. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rev :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Reverse characters on each line (rev) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
revW :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
space :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Double space a file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
unspace :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tac :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Reverse lines in a String (like Unix tac). Implemented as: tac = reverse See uniq. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tee :: [FilePath] -> String -> IO String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Takes input, writes it to all the specified files, and passes it on. This function buffers the input. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
teeBS :: [FilePath] -> ByteString -> IO ByteString | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lazy ByteString version of tee. This function does NOT buffer input. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
teeFIFOBS :: [FilePath] -> ByteString -> IO ByteString | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FIFO-safe version of teeBS. This call will BLOCK all threads on open until a reader connects. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tr :: Char -> Char -> String -> String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Translate a character x to y, like: tr 'e' 'f' Or, in sed, y// | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
trd :: Char -> String -> String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Delete specified character in a string. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
wcW :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
wcL :: [String] -> [String] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Count number of lines. wc -l | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
uniq :: String -> String | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Remove duplicate lines from a file (like Unix uniq). Takes a String representing a file or output and plugs it through lines and then nub to uniqify on a line basis. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Produced by Haddock version 0.8 |