Search Results

Search: Posts Made By: Ray Sun
9,807
Posted By MadeInGermany
1 is default; you can do echo "$i does not...
1 is default; you can do
echo "$i does not exist!" >&2
9,807
Posted By franzpizzo
The redirect to the standard is echo "Error"...
The redirect to the standard is

echo "Error" 1>&2

so

#!/bin/bash
if [ $# -lt 1 ] ; then #Check there is enough command line parameters.
echo "Not enough command line parameters" 1>&2...
1,904
Posted By elixir_sinari
In bash, the piped processes run in sub-shells....
In bash, the piped processes run in sub-shells. So, the second exit 1 is only affecting the sub-shell running the while loop and not your whole script.

Try a variant such as:
...
while read i;...
1,904
Posted By fpmurphy
It is due to the fact that you are using a...
It is due to the fact that you are using a pipeline.

To see the difference, change your code to:

#!/bin/bash

if [ $# -lt 1 ] ; then #Check there is enough command line parameters.
...
2,799
Posted By juzz4fun
Will this work for you? Content of program: ...
Will this work for you?

Content of program:
awk '{print $2" " $1}'

then you execute it like..

./program < input.in > output

This will output as..

cat output
b a
2,799
Posted By Don Cragun
Change the contents of program from: echo $2...
Change the contents of program from:
echo $2 $1to:read a1 a2 junk; echo $a2 $a1or, if the contents of input.in could contain characters with special meaning to the shell (including backslash (\) or...
2,799
Posted By bakunin
Quite simple: "$1" (2, 3, ...) are variables...
Quite simple: "$1" (2, 3, ...) are variables which are filled with COMMANDLINE ARGUMENTS, whereas what you are redirecting to/from is INPUT and OUTPUT respectively. These are simply two different...
2,306
Posted By Chubler_XL
Yes, but beware if you have a large number of...
Yes, but beware if you have a large number of files that match.
The ls solution will fail with an "argument list is to long" error. The for solution is immune to this issue.
1,617
Posted By Chubler_XL
You could also use bash extend globbing: ...
You could also use bash extend globbing:

bash$ shopt -s extglob
bash$ ls
AB AC AD AE B C
bash$ ls !(AB*|?)
AC AD AE
2,306
Posted By Chubler_XL
The shell can also do this directly without...
The shell can also do this directly without calling find or ls:

for FILE in */*.c
do
[ -f "$FILE" ] || continue
echo "$FILE"
: process the file(s)
done

Also, if you are only...
2,306
Posted By Yoda
Both approaches are right. You can also use...
Both approaches are right.

You can also use ls command to list .c files in all sub-directories:
ls -1 */*.c
1,617
Posted By Scrutinizer
Your understanding is correct for the first part,...
Your understanding is correct for the first part, but
[!A]?* A[!B]*
Are two patterns that produce one field list, so it is not the command that glues them together. These fields are input to the...
1,617
Posted By Scrutinizer
Ow yes, that will also not list files that start...
Ow yes, that will also not list files that start with "A" . This should work better:
ls [!A]?* A[!B]*
1,146
Posted By Yoda
awk '{print "(t.who = \x27" $1 "\x27 and...
awk '{print "(t.who = \x27" $1 "\x27 and trunc(ymddate) = to_date(\x27" $7"-"$8"-"$NF"\x27,\x27mon-dd-yyyy\x27)) or"}' file
Showing results 1 to 14 of 14

 
All times are GMT -4. The time now is 08:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy