Tag Info

New answers tagged

2

for f do exec <"$f" : handle stdin done A non-interactive shell will treat any redirection from a file that cannot be read or that does not exist when associated w/ a special builtin as a fatal error and exit immediately with a meaningful diagnostic message written to stderr. So either your parameters are valid, readable files and the above ...


0

first_file="$1" test -f "$first_file" || exit 2 file_content="$(<"$first_file")" echo "$file_content"


-1

You can do it: #!/bin/bash while read line ; echo "$line" ####### ####### ######## done < "$1" description: each $line is a content of complete line of your file. usage : ./script.sh file.txt


0

Some example are here. You can use them.


1

find . -type f | while read file; do echo "${file##*.}"; done Has the advantage of bypassing all that tricky exec syntax that no one can ever remember. Also has the advantage of only creating one child process, instead of creating and destroying one for every found file. This is considerably faster than jimmij's version using exec # Preparation - 1000 ...


2

If you want to use shell parameter expansion then run some shell with exec: find . -type f -exec sh -c 'echo "${0##*.}"' {} \;


1

That's typically what xargs is for: xargs myscript.sh < mydata xargs considers the input as blank or newline separated words where single quote, double quote or backslash is used to escape the separators. xargs will run the command as many times as necessary so as to avoid the limit on the size of arguments (and environment) passed to a command.


1

"$(cat mydata)" evaluates to a string which contains the content of the file mydata minus any trailing newline. What you want is the list of whitespace-separated words in the file. So, for once, use the command substitution outside of double quotes: myscript.sh $(cat mydata) For extra robustness, turn off globbing, so that if a column in mydata contains ...


1

Instead of passing as multiple arguments, I just pass the arguments as a single array and then do whatever I want with the arguments. #This is the function which takes a variable length array as an input. function function_call() { all_array_values=$1[@] a=("${!all_array_values}") for i in "${a[@]}" ; do echo "$i" done } #Here I ...



Top 50 recent answers are included