The official home of the Python Programming Language. Compound Data Types. Lists (known as arrays in other languages) are one of the compound data types that Python understands. The official home of the Python Programming Language. Compound Data Types. Lists (known as arrays in other languages) are one of the compound data types that Python understands.
This script, which is obviously not mine, appears to do the same thing whether the 1&2 is there or not. I'm curious what purpose it serves.#!/bin/bash# cmpdir - program to compare two directories# Check for required argumentsif $# -ne 2 ; thenecho 'usage: $0 directory1 directory2' 1&2exit 1fi# Make sure both arguments are directoriesif ! -d $1 ; thenecho '$1 is not a directory!'
1&2exit 1fiif ! -d $2 ; thenecho '$2 is not a directory!' 1&2exit 1fi# Process each file in directory1, comparing it to directory2missing=0for filename in $1/.; dofn=$(basename '$filename')if -f '$filename' ; thenif ! -f '$2/$fn' ; thenecho '$fn is missing from $2'missing=$((missing + 1))fifidoneecho '$missing files missing'. Cat does not have any parameters, so it will read standard input, in this case: inputfile (. Will send the content of somefile to standard output, which is then displayed into the terminal window. And if somefile does not exist, an error message will be sent to standard error, which will then be displayed into the terminal.Now let's imagine that somefile is a list of errors generated by some other tool.
You want cat to display the list of errors, but cat was created to send the file content to standard output, not standard error! The solution is to make the shell redirect cat's standard output to its standard error: cat somefile 1&2.
This will give you the number of output lines. The 'tee' command mainly outputs what was output by the previous command. So tee is not a filter, no information is lost; tee is just there to also store the standard output to referencefile.As a normal user (not root), you're bound to have at least some errors with this command.
You'll see that the number you'll get is not the number of lines of error that you saw. But this number should be the same as the result of this command: cat referencefile wc -l. And if you look at this file, you'll see there are no errors in it.
This is because the 'pipe' command (the symbol) only lets the standard output go through, not standard error.This all means that the system is able to distinguish output from errors, even though they both look the same to us. That is sometimes very usefull. Imagine you want to find all files in /home, the name of which contains 'file' (eg: myfile.txt,.profile.). You'll run this command: find /home -name '.' -print grep 'file' listfound.txt.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |