Can Somebody Please Help Me Clarify This Paragraph...

Bash interactive behavior is started when the bash command is called upon without non-option arguments, except when the option is a string to read from or when the shell is invoked to read from standard input, which allows for positional parameters to be set.


Similar Content



Bash Script Non-interactive Login Shell

Hi

I'm focusing on getting my head around interactive v non-interactive shells, both non-login and login. Basically what scripts are run and how local and global variables behave.

I'm pretty much there except for 'non-interactive login shells'. I understand that 'non-interactive' shells are started when a script is run. However, if I start my script with #!/bin/bash --login, then a 'non-interactive login' shell will be started.

In my mind I would have expected this to be the same as logging in from scratch, albeit without a user\password prompt. In this case I would have thought that any exported variables from the parent shell would be blown away. This doesn't appear to be the case. The 'non-interactive login' shell appears to inherit the environment of its parent 'interactive' shell.

Can anyone explain the purpose of a 'non-interactive login' shell and how they behave in this regard.

Hope this makes sense.

Cheers

Mike

W Command Certain Columns

I am looking to display the w (who) command to show only the

User TTY IDLE


http://screencast.com/t/vXb74kguJ

13:15:38 up 8 days, 16:48, 47 users, load average: 1.47, 0.95, 0.51
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
rf3 pts/0 192.168.11.72 05:58 48.00s 6.60s 0.00s -bash
user21 pts/1 192.168.21.177 04:32 8:41m 0.05s 0.00s -bash
user7 pts/2 192.168.11.114 17Mar15 6days 1.07s 0.00s -bash
user7 pts/3 192.168.11.114 20Mar15 4:54m 9.75s 0.00s -bash
user6 pts/4 192.168.11.85 11:02 7.00s 55.58s 0.01s -bash
user14 pts/5 192.168.11.183 05:06 29:08 2.80s 0.01s -bash
user14 pts/6 192.168.11.155 05:30 13:28 2.75s 0.00s -bash
user23 pts/7 192.168.11.62 05:48 25:09 0.95s 0.00s -bash
rf5 pts/8 192.168.11.118 05:58 6:51 5.30s 0.01s -bash
user2 pts/9 192.168.11.140 08:34 1:19 44.74s 0.00s -bash
user14 pts/10 192.168.11.141 06:02 12:14 9.46s 0.00s -bash
rf12 pts/12 192.168.11.69 06:02 2:07 9.44s 0.00s -bash
root pts/13 localhost.locald 12:29 9:10 0.05s 0.05s -bash
rf6 pts/14 192.168.11.79 06:04 14.00s 9.05s 0.00s -bash
user14 pts/15 192.168.21.113 06:23 11:29 1.71s 0.00s -bash
user5 pts/16 192.168.11.126 06:24 6:56 4.59s 0.00s -bash
user5 pts/17 192.168.11.126 06:25 6:19 31.59s 0.01s -bash
user11 pts/18 192.168.11.125 06:26 28:10 2.90s 0.01s -bash
user12 pts/19 192.168.21.123 06:35 13:16 0.88s 0.00s -bash
rf7 pts/20 192.168.11.80 06:35 2:06 7.64s 0.00s -bash
user12 pts/21 192.168.21.123 06:36 41:55 0.12s 0.00s -bash



So far I have this

w | awk {'printf ("6s\ts\n", $1, $2, $3, $5)'} |more
13:20:16 up
USER TTY
rf3 pts/0
user21 pts/1
user7 pts/2
user7 pts/3
user6 pts/4
user14 pts/5
user14 pts/6
user23 pts/7
rf5 pts/8
user2 pts/9
user14 pts/10
rf12 pts/12
root pts/13
This only shows the 2 columns



w |awk '{print $1, $2, $3, $5}'

13:21:01 up 8 16:53,
USER TTY FROM IDLE
rf3 pts/0 192.168.11.72 20.00s
user21 pts/1 192.168.21.177 8:46m
user7 pts/2 192.168.11.114 6days
user7 pts/3 192.168.11.114 4:59m
user6 pts/4 192.168.11.85 3:42
user14 pts/5 192.168.11.183 34:31
user14 pts/6 192.168.11.155 18:51
user23 pts/7 192.168.11.62 30:32
rf5 pts/8 192.168.11.118 12:14
user2 pts/9 192.168.11.140 1.00s
user14 pts/10 192.168.11.141 17:37
rf12 pts/12 192.168.11.69 30.00s
This shows some what hard to read and the columns don't line up correctly


is there a way to tab them in to columns that line up properly, or even something similar to the TOP command where the list will keep refreshing?

.profile And Bash.rc

hi guys

i was taught that /etc/profile was global for environmental variables and settings...and ~/.profile was specific to the user...

and that bash.rc and ~/.bash.rc was for aliases and functions...i was trying to setup a permanent alias in my profile to a common ssh command and read that it should be going into .profile??? is it really not strict or just a rule of thumb?

Is There A Way To Have A Script Called Source, That Can Be Run Without The Full Path?

Is there a way to have a script called source, that can be run without the full path?

Ex:
When I run:
export PATH=/home/user:$PATH
source

I get:
Code:
$ source
bash: source: filename argument required
source: usage: source filename [arguments]

However I want it to run my script called source:
Code:
$ cat source 
#!/bin/bash
echo "Hello World"

Is there way to override a shell builtin in the PATH var or some other way?

Value Comparison In Bash Shell Script

I need to compare a value with different fixed value. Below is the code concept I implemented in my bash script but its giving me error.
Here "a' is the nameserver value that I extract using command line from /etc/resolv.conf. I did not put command here.

#! /bin/bash
a=1.2.3.4

if [ $a == 1.2.3.4 || 5.6.7.8 || 8.9.1.4]
then
echo " You have correct ntpserver"
else
echo"wrong ntpserver"

fi

Am I comparing the value correctly or any suggestion?

Thank you

Bash Covertly Executing Command

Hi all,

So ever since I installed livestreamer yesterday, oftentimes when I execute a command in bash it seems to be executing livestreamer and treating everything I actually entered as arguments. For example, I will type

sudo emerge -cav livestreamer

and I will get an error messaging advising me not to run livestreamer as root.

This seems to happen 100% of the time when the command I intend to issue refers to livestreamer in any way, and only some of the times when it doesn't.

I'm pretty new to linux, and I've been able to google my way out of a few problems so far, but this one has me baffled. I've checked my bashrc file for things out of the ordinary, but to no avail. Any and all help would be really appreciated. If I've left anything out let me know.

How To Return From Shell 'read' Command Passed In Expect Script?

I have a shell script that calls an expect script I wrote to ssh login to another host and get user input regarding that host's network configuration. I pass four arguments to the expect script: the remote host ip address, the username, the password, and the list of commands to run. My expect script is below:

#!/usr/bin/expect
# Usage: expectssh <host> <ssh user> <ssh password> <script>

set timeout 60
set prompt "(%|#|\\$) $"
set commands [lindex $argv 3];

spawn ssh [lindex $argv 1]@[lindex $argv 0]

expect {
"*assword:" {
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

"you sure you want to continue connecting" {
send -- "yes\r"
expect "*assword:"
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

timeout {
exit }

expect -re $prompt
send -- "exit\r"
}

The script runs well, except that if I send a command such as 'read' that requires user input, the script does not continue or exit after the user presses enter. It just hangs.

The commands I pass to the expect script and it's call are as follows:
SCRIPT='hostname > response.txt;netstat -rn;read net_card?"What is the network interface card number? " >> response.txt; read net_mask?"What is the subnet mask? " >> response.txt'

/usr/bin/expect ./expectssh.exp $hostip $usr $pswd "$SCRIPT"

Any suggestions on how I can pass a command to my expect script that requires user input without it hanging?

On a side note because I know it will come up - I am not allowed to do key-based automatic SSH login. I have to prompt for a username and password, which is done from my main shell script.

Thanks for any suggestions and help you can provide!

Where Does The Bash Command Stop

hi guys, im trying to understand the bash rules or hash tag rules.

my understanding is the the everything to the right of the bash command is not executed? is this right? and you disable it by using a new line to enter executable commands?

Would Like To "echo" A Line, "read" Reply, Then Execute The Reply: How In Bash?

Apologies. I've been out of Unix for 14 years, and the gears have rusted. Also, Unix has changed - enough similarities to memory that I'm pretty comfy though.

Glad to see lots of info available via google. However changes are going to take getting used to. Have set up a testbed of 3 nearly identical machines, hoping to make an (at home) private network where I can automate installs and set-ups using NIS and NFS (Similar to work I once did).

Have found useful scripts interspersed with comments, would like to copy and paste them to a bash script that:

Reads the line.
Echos the line.
Reads the reply.
Executes what is typed.

Essentially, by making myself type (or copy & paste) the commands I think I'll become familiar.

Figured I'd use a spreadsheet, select the file, and paste into column B of the spreadsheet. In column A I'd paste:

echo "

and in column C I'd paste:

"

Then I'd cut and paste into a text document, insert the lines:

read A
$A

behind every command necessary to the actual task.

Figured I'd have to escape the ' and ".

Ran a test (test.bash):

#!/bin/bash
for i in `seq 1 10`;
do
echo "Enter a command:"
read A
echo "Trying $A"
$A
done

works fine when I type

ls -alg

but not so when I type

ls -alg | grep dwrx

so I'm wondering if someone has a suggestion?

Thanks for any ideas.

How Can I Get Shell To Read Special Characters As Strings? Such As $ Or !

How can I get shell to read special characters as strings? Such as $ or !

Code:
$ ./test.sh "!hooray!"
bash: !hooray!: event not found
$ ./test.sh !hooray!
bash: !hooray!: event not found

If I escape it, the \ prints in the output:
Code:
$ ./test.sh "\!hooray\!"
\!hooray\!

The code of test.sh is as follows:
Code:
$ cat test.sh 
#!/bin/bash
str="$1"
echo "$str"

TIA