Shell ${1:-/etc/hosts} meaning


 
Thread Tools Search this Thread
Operating Systems Linux Shell ${1:-/etc/hosts} meaning
# 1  
Old 07-19-2013
Shell ${1:-/etc/hosts} meaning

Hello. In some script, I saw:

Code:
filename=${1:-/etc/hosts}
if [ -r “$filename” ] && [ -s “$filename” ]; then
md5sum $filename
else
echo “$filename can not be processed”
fi
# Show the file if possible
ls -ld $filename 2>/dev/null

What does the first line means? In $filename I still got /etc/hosts.
# 2  
Old 07-19-2013
If no arguments are passed to this script or if the 1st argument passed to this script is an empty string, the shell variable filename will be set to "/etc/hosts"; otherwise the 1st argument passed to the script will be assigned to filename.

So, if your script is named some and you invoke it as:
Code:
./some
    or as
./some ""

then filename will be set to /etc/hosts, but if you invoke it as:
Code:
./some /etc/motd

then filename will be set to /etc/motd.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 3  
Old 07-19-2013
I understand it completely. Thank you! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to copy a tar file on a series of remote hosts and untar it on those hosts?

Am trying to copy a tar file onto a series of remote hosts and untar it at the destination. Need to do this without having to do multiple ssh. Actions to perform within a single ssh session via shell script - copy a file - untar at destination (remote host) OS : Linux RHEL6 (3 Replies)
Discussion started by: sankasu
3 Replies

2. Shell Programming and Scripting

Meaning of =~ in shell script

Please let me understand the meaning of following line in unix bash scripting .is =~ means not equal to or equal to . if ]; then echo -e "pmcmd startworkflow -sv ${INTSERV} -d ${INFA_DEFAULT_DOMAIN} -uv INFA_DEFAULT_DOMAIN_USER" \ "-pv INFA_DEFAULT_DOMAIN_PASSWORD -usdv... (2 Replies)
Discussion started by: harry00514
2 Replies

3. Shell Programming and Scripting

What is the meaning of ## in UNIX shell script?

Hi All, I am new to unix shell scripting and I was documenting one of the unix script and encountered below statements - for ii in `ls -1rt /oracle/admin/MARSCOPY/ext_files/fpm-ifpm/*.small.txt | tail -1 | awk '{print $1}'` do smallssim=${ii##/oracle/admin/MARSCOPY/ext_files/fpm-ifpm/}... (2 Replies)
Discussion started by: shuklajayb4
2 Replies

4. Shell Programming and Scripting

SSH to remote hosts in shell scripting

Hi There, I have a file contaning some 100 servers names one by one the file called redhat_servers.txt I want to prepare a script where it should give me the host name and kernal version. I wrote like this, #!/bin/bash while read line do ssh $line "uname -nr" done <... (3 Replies)
Discussion started by: kumar85shiv
3 Replies

5. Shell Programming and Scripting

Ssh to 100s of hosts with password in a shell script or text file

I have about 500 hosts where I need to ssh by sending the password on the command line or in a text file in a clear text . However I am not able to download "sshpass" or other tools . Any other ways to pass the password in a script ? (3 Replies)
Discussion started by: gubbu
3 Replies

6. AIX

aix tcp wrappers hosts.allow hosts.deny?

hi all just installed the netsec.options.tcpwrapper from expansion pack, which used to be a rpm, for my aix 6.1 test box. it is so unpredictable. i set up the hosts.deny as suggested for all and allow the sshd for specific ip addresses/hostnames. the tcpdchk says the hosts allowed and... (0 Replies)
Discussion started by: wf201626
0 Replies

7. Shell Programming and Scripting

Communication between different hosts through shell scripts.

1) I have two scripts named as a.sh,b.sh running two different hosts host1 and host2 2) So now how to execute b.sh on host2 from a.sh on host1 3) Also I have few queries regarding the same as I want to execute few commands with sudo and with different user in script b.sh so how this can be... (2 Replies)
Discussion started by: RSC1985
2 Replies

8. Shell Programming and Scripting

Help with shell script which logins to hosts

By a shell script When I am logging into hosts one by one with ssh. I am getting below message. Pseudo-terminal will not be allocated because stdin is not a terminal. stty: : Invalid argument stty: : Invalid argument Can you please suggest what should I do to stop this? ... (10 Replies)
Discussion started by: KuldeepSinghTCS
10 Replies

9. Shell Programming and Scripting

meaning of & in sh shell

All, I have a line in my code like below , could any one please tell me what this actually mean what is the & doding there. I am in sh shell #!/bin/sh .............. mv &fname &III.tar.gz Thanks in Advance, Arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

10. UNIX for Dummies Questions & Answers

meaning of .& in shell

Hi , can anyone explain me the meaning of following line ". &13FNAME/version_encours/cfg/dfm.cfg" Regards (1 Reply)
Discussion started by: scorpio
1 Replies
Login or Register to Ask a Question