Apologies if this is a basic concept, but I was wondering how to incorporate the userinput immediately after running the code. Same line, no prompt.  I tried:   #!/bin/bash   read userinput   but that results in reading the userinput in the next line over. i.e. (assuming UserInput is 2):  $./programname 2     For reference, I want to essentially type:  $./programname 2   directly into the command line, without a newline.
1384
Say, I have a script that gets called with this line: ./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile  or this one: ./myscript -v -f -d -o /fizz/someOtherFile ./foo/bar/someFile   What's the accepted way of parsing this such that in each case (or some combination of the two) $v, $f, and  $d will all be set to true and $outFile will be equal to /fizz/someOtherFile?
82241
Suppose I have a script like this:   (The example depicts an rysnc use case)  #!/bin/bash echo -n "Enter Source Directory:" read srcdir echo -n "Enter Destination Directory:" read dstdir rsync -av --delete "$srcdir" "$dstdir"   The idea here is to prompt the user to enter the "Source" and "Destination" directories for rsync to work with. As is, the user will have to manually enter /path/to/directory/ via the command-line.  Instead, I want to prompt the user to enter the paths through a GUI interface.  Something like this:     What commands can I use to prompt the user with a GUI selection window that returns the file path to the command-line?
36570
Is there an easy way to change my Bash prompt to modify the colors and what text is displayed? I've heard that this is done in .bashrc, but I haven't found any nice, easy ways of modifying it. How are colors expressed in Bash?
31975
What can explain the examples below and how do I fix this, preferably without heavy quoting acrobatics? I am using the $n to simulate multiple line command strings, just in case it distracts you from the real question.  ~$ n=$'\n'; sudo -i echo "line1${n}line2${n}" line1line2 ~$   but  ~$ n=$'\n'; sudo echo "line1${n}line2${n}" line1 line2  ~$
20796
I was wondering where I can find and learn some general idea about the command line interface used in Linux and bash? As to now, I have found pieces of such information only from experience, such as   For cat, without any further arguments, it accepts stdin input. But you may explicitly specify STDIN using the special name -, and both ways are equivalent. cat can also accept a filename as cat filename. So is - meant to fill in an argument supposed for filename? Is this usage of - also common for other commands? In chardet &lt;&lt;&lt;somestring, &lt;&lt;&lt; means a string  is used as stdin, the same as echo somestring | chardet. Is this usage of &lt;&lt;&lt; also common? In cut -c 1-3,20,25- employees, is the way 1-3,20,25- to specify a range of numbers for an argument also common in other commands?  Last but not least,  are these general ideas common to just within bash, or within Linux and Unix, or within software using getopt as command line parser?
13559
I wonder why some similar bash commands behave the way they do.  I have a bash script foo:  #!/usr/bin/env bash  while true do     echo "reading"     read data     echo $data     echo "stderr msg" &gt;&amp;2     sleep 1 done   It's an infinite loop which reads one line at a time from stdin and outputs that same line. I also have a bash script bar:  #!/usr/bin/env bash  ./foo &amp;   The following commands were run in bash (v. 4.4.19) in a terminal on Ubuntu 18.04 (let's assume the scripts reside in the working directory):   ./foo &amp;   Stops when it tries to read from stdin, in accordance with . Killed when controlling terminal is killed, as expected.  (./foo &amp;)   Appears to be automagically continuously fed with new input from stdin. Shouldn't it too stop when attempting to read from stdin? Whatever it's getting it doesn't show when echoed, thus I'm guessing it's EOF characters.  Continues running even after the controlling terminal is killed. Looking at the output of ps, the controlling terminal changes from pts/x to ?. How did this happen without the use of either disown or nohup? (However, after killing the originally controlling terminal, it yields a "write error: Input/output error" on every write, which I suppose is because its stdout was tied to the now closed terminal. Correct?)  bash -c "./foo &amp;"  Appears to behave exactly like 2). ./bar  Appears to behave exactly like 2) and 3). Adding bash -c "~/foo" (no &amp;) as a startup application  Behaves similarly to 2), 3) and 4), with the differences:   Its controlling terminal is the desktop ttyx. You can't (can you?) kill its controlling terminal.   None of those differences seem odd to me, just the fact that it's continuously fed with new input.   My guess is that 2) - 5) all use a subshell of sorts whose stdin is redirected to something like /dev/null, though I'm very unsure and seek a more exact answer.
84776
I was just curious if there's a way to get input not from StdIn but from $EDITOR - be it vim, nano, emacs or even a non-command-line-editor (MacVim/TextMate). What are the options/workarounds/bestpractices?  Basically I'd wish for a workflow as with heredoc - but from the $editor instead.   $ sort -nr &lt;&lt; FOO | uniq -c  pipe heredoc&gt; foo  pipe heredoc&gt; bar pipe heredoc&gt; baz pipe heredoc&gt; foo pipe heredoc&gt; FOO    2 foo    1 baz    1 bar
19648
abhigenie92@ubuntu:~$ (sleep 2; echo $BASH_SUBSHELL ;sleep 2) 1 abhigenie92@ubuntu:~$ (sleep 2; echo $BASH_SUBSHELL ;sleep 2)&amp; [1] 3297 abhigenie92@ubuntu:~$ 1  [1]+  Done                    ( sleep 2; echo $BASH_SUBSHELL; sleep 2 )   What happens when launch it as a background process, why don't I get the prompt back and I have to press Enter? In both cases it launches a child shell.
108441
I have been learning bash, and while doing so I played around with the .bash_profile file to be able to put greeting messages etc. Later I just removed these changes. But after doing that my default configuration of prompt got lost: originally, the prompt was all in bold, and \w part was blue so that when I was in a deeply nested directory the prompt would not seem so entangled. I think that was the default for Ubuntu (correct me if i'm wrong), however like  I said it got lost and my prompt was non-bold and monochromatic resulting in a mess when I'm in long named directories.  So, last night I tried customizing my prompt in the fashion I mentioned above. It worked well after I added the code to .bash_profile  Code was like this:  export PS1="\[$(tput bold)\]\u@\h:\[$(tput sgr 0)\]\e[1;34m\w$ \e[m"   However if I try to run another bash shell in the current one, the prompt becomes unformatted:    Is that normal? Isn't the whole point of exporting a variable to make it accessible from all the child processes forked from that shell? Why it doesn't that apply to this situation?
99211
I am doing some challenges. This is one them. I am trying to brute-force 4 digit pin with the password to get my desired answer. After connecting to the port It prompts me to enter the password then space then 4 digit pin. I tried to brute-force the pin using the script:  #!/bin/bash   nc localhost 30002   sleep 2    for i in {0000..9999};       if [[ $(echo 'UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $i' &lt;/dev/stdin) = ^Wrong*]];                         then          continue       echo '[+] Pincode Cracked! Pincode = $i'       fi   done  but it seems that this doesn't input the pass and pin to stdin, before i tried doing something like this -&gt; if [[ $(echo 'UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $i') = ^Wrong* ]]; What am I doing wrong here? UPDATE: Okay, so after researching around. I wrote this: for i in {0000..9999} do     if [ (echo &quot;UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $i&quot; | nc localhost 30002 | grep -o Wrong) == &quot;Wrong&quot; ]    then       sleep 0.1       continue    fi    echo &quot;- - - - - - - - - - - - - - - - - - - - - - - - [$i]&quot; done  This might even work but as you can see it opens new connections in the loop which makes it really slow and exhaust the system.
83138
If I issue the trap builtin twice [for the same signal], what happens? Is the second command added to the first, or does it replace the first?  trap Foo SIGINT ... trap Bar SIGINT ...   When SIGINT happens, does Bash just run Bar, or does it run Foo as well? Or something else...?
119193
Is there a command prompt  equivalent for Windows 7? That is, I want to filter out the results of a command:  Bash use:  ls | grep root  What would it be from a Windows command prompt?
92435
Is it possible to call a script in this example named hey.sh after every bash command?  For example you type ls hit enter and ls runs, then hey.sh would run.  You then type cd .. (or any other command), cd runs then hey.sh would run, and so on.
31776
In sh (not Bash), how would we abort execution of command when the prompt is in &gt; mode?  For example, when entering a string with quotes only at the beginning, it makes the prompt look like &gt;, without the ability to quit it normally, unless hitting Ctrl + D. Example:  root@MyPC:~# echo "hello &gt; I am &gt; (How do I exit of this mode?)   In case that I don't know which character delimits the string (" or ' or simply escaping a newline/spaces with backslash), is there a way to let Bash know that I want to abort the execution of the current command?
55413
The question is pretty straight forward. I can get the exit code of the previous command by using $?. But what exactly is it?  I don't think it is a variable, because you can't have any special characters in the name of variable other than _.  foo?foo=10   will result in the error: foo?foo=10: command not found  So if it is not a variable, what is it? Are there others like it?
44526
I don't use bash often but I recall in the past to pass a tab or newline on the command line I would have to escape the character using the special $ character before a single quoted string. Like $'\t', $'\n', etc. I had read about   What I want to know is when it's appropriate to use an ANSI C style escape. For example I was working with a regex in grep and it appeared I needed an ANSI C style escape for a newline. Then I switched to perl and it seemed I didn't.  Take for example  about a perl regex that didn't work. Here's the regex I was using:   echo -e -n "ab\r\ncd" | perl -w -e $'binmode STDIN;undef $/;$_ = &lt;&gt;;if(/ab\r\ncd/){print "test"}'   It turns out that is actually incorrect because I gave the string ANSI C style escape by using $. I just don't understand when I'm supposed to prepend the dollar sign and when I'm not.
99729
Here's my test bash script. I'm not able to get it to work. I'm seeing two errors:   Use of uninitialized value $answer in chop at /usr/sbin/adduser line 589. Use of uninitialized value $answer in pattern match (m//) at /usr/sbin/adduser line 590.   Here's my script:  #!/bin/bash sudo adduser myuser &lt;&lt; ENDX password password First Last     Y ENDX exit 0   Here is the output:  me@mycomputer$ ./adduser.sh  Adding user `myuser' ... Adding new group `myuser' (1001) ... Adding new user `myuser' (1001) with group `myuser' ... Creating home directory `/home/myuser' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for myuser Enter the new value, or press ENTER for the default         Full Name []:   Room Number []:         Work Phone []:  Home Phone []:  Other []: Use of uninitialized value $answer in chop at /usr/sbin/adduser line 589. Use of uninitialized value $answer in pattern match (m//) at /usr/sbin/adduser line 590. Is the information correct? [Y/n] me@mycomputer$   This is on Kubuntu 12.04 LTS  $ bash --version bash --version GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)   Here are the lines from adduser (system script - unmodified by me) with notations of the two relevant line numbers:  for (;;) {        my $chfn = &amp;which('chfn');     &amp;systemcall($chfn, $new_name);     # Translators: [y/N] has to be replaced by values defined in your     # locale.  You can see by running "locale yesexpr" which regular     # expression will be checked to find positive answer.     print (gtx("Is the information correct? [Y/n] "));     chop (my $answer=&lt;STDIN&gt;);        &lt;-- LINE 589     last if ($answer !~ m/$noexpr/o); &lt;-- LINE 590 }