I am trying to write a tiny script that accepts any number of command line arguments that prints permissions rwxfor a file (not a directory)
rwx
I have
file=$@ if [ -f $file ] ; then ls -l $file fi
However, it accepts only one command line argument. Thanks for any help.
Here is a demonstration of some of the differences between $*and $@, with and without quotation marks:
$*
$@
#/bin/bash for i in $*; do echo "\$*: ..${i}.." done; echo for i in "$*"; do echo "\"\$*\": ..${i}.." done; echo for i in $@; do echo "\$@: ..${i}.." done; echo for i in "$@"; do echo "\"\$@\": ..${i}.." done; echo
Launch:
user@host$ ./paramtest abc "space here" $*: ..abc.. $*: ..space.. $*: ..here.. "$*": ..abc space here.. $@: ..abc.. $@: ..space.. $@: ..here.. "$@": ..abc.. "$@": ..space here..
How about this:
for file do test -f "$file" && ls -l "$file" done
for $@, . , "$ file" , . , script 'myll.sh':
$ myll.sh "My Report.txt" file1 file2
"My Report.txt" : "" "Report.txt"
$@ - , ( ). ($* - , , ).
, . , ls.
ls
for file in "$@"; do if [ -f "$file" ]; then ls -l "$file" fi done
: $@ ! $file - . $@ , file , -f ']'. .
$file
file
, , , ls ( if), :
if
ls -l "$@"
, :
for file in "$@"; do ls -l "$file" done
, , :
for file in "$@"; do if [ ! -d "$file" ]; then ls -l "$file" fi done
bash , script, "$ *". :
for file in $*; do if [ -f $file ] ; then ls -l $file fi done
( )
Source: https://habr.com/ru/post/1659458/More articles:Packages are unsatisfied when I try to install nginx - ubuntuMismatch ranking: the rank of labels (received 2) should be equal to the rank of logins minus 1 (received 2) - pythonMultiple Timers in UITableViewCell (Swift) - iosChange opacity on part of geom_bar - rHow to create a choropleth map using plot_geo ()? - dictionaryPayment works with a strip on LocalHost, but do not work on Heroku - ruby-on-railsEntity Framework One to Many Relationships - c #How to center the `layout =" row "` div? - angularjsWhy don't my maven nested dependencies appear at compilation - javaHow to store a PHP object in memory (or in memory) between AJAX calls - phpAll Articles