i have an error that says line 17: unexpected end of file. i know others have already asked this, i tried to do the solutions given to them but still i am having the error. i am using ubuntu server 16.04 LTS. i used nano editor to write my bash.sh file. and i also downloaded the dos2unix already.  did the command sudo dos2unix bash.sh, it says converting file bash.sh to unix format...  after i do this i try to run again  using sudo ./bash.sh usertest and i still have an error  my code is very simple just to test an argument:  USER=$1  DATE=`date +%d%m%y`  if [ -z "$1" ];then     echo "Wrong format"    exit 1 else    if [ -d "\home\$USERNAME" ]; then      echo "correct" fi
121902
I have typed out the code for this mychoice.sh bash example and I keep getting the syntax error: unexpected end of file.  Am I missing something?  mychoice.sh  #!/bin/bash  E='echo -e';e='echo -en';trap ";exit" 2 ESC=$( $e "\e") TPUT(){ $e "\e[${1};${2}H";} CLEAR(){ $e "\ec";} CIVIS(){ $e "\e[25l"} DRAW(){ $e "\e%\e(0";} WRITE(){ $e "\e(B";} MARK(){ $e "\e[7m";} UNMARK(){ $e "\e[27m";} R(){ CLEAR ;stty sane;$e "\ec\e[37;44m[J";}; HEAD(){ DRAW     for each in $(seq 1 13);do     $E "   x                    x"     done     WRITE;MARK;TPUT; 1 5     $E "BASH SELECTION MENU         ";UNMARK;}     i=0; CLEAR; CIVIS;NULL=/dev/null FOOT(){ MARK;TPUT 13 5     printf "ENTER - SELECT,NEXT         ";UNMARK;} ARROW(){ read -s -n3 key 2&gt;/dev/null &gt;&amp;2      if [[$key = $ESC[A ]];then echo up;fi      if [[$key = $ESC[B ]];then echo dn;fi;} M0(){ TPUT  4 20; $e "Login info";} M1(){ TPUT  5 20; $e "Network";} M2(){ TPUT  6 20; $e "Disk";} M3(){ TPUT  7 20; $e "Routing";} M4(){ TPUT  8 20; $e "Time";} M5(){ TPUT  9 20; $e "About  ";} M6(){ TPUT 10 20; $e "Exit   ";} LM=6 MENU(){ for each in $(seq 0 $LM);do M${each};done;} POS(){ if [[ $cur == up ]];then ((i--));fi     if [[ $cur == dn ]];then ((i++));fi     if [[ $i -lt 0 ]];then i=$LM;fi     if [[ $i -gt $LM ]];then i=0;fi;} REFRESH(){ after=$((i+1)); before=$((i-!))     if [[ $before -lt 0 ]];then before=$LM;fi     if [[ $after -gt 0 ]];then after=0;fi     if [[ $j -lt $i ]];then UNMARK;M$before;else UNMARK;M$after;fi     if [[ $after -eq 0 ]] || [$before -eq $LM ];then          UNMARK; M$before; M$after;fi;j=$i;UNMARK;M$before;M$after;} INIT(){ R;HEAD;FOOT;MENU;} SC(){ REFRESH;MARK;$S;$b;cur='ARROW';} ES(){ MARK;$e "ENTER = main menu ";$b;read;INIT;};INIT while [[ "$0" != " " ]]; do case $i in     0) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(w     )\n";ES;fi;;     1) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(ifconfig  )\n";ES;fi;;     2) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(df -h )\n";ES;fi;;     3) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(route -n  )\n";ES;fi;;     4) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS(date  )\n";ES;fi;;     5) S=M2;SC;if [[ $cur == "" ]];then R;$e "\nS($e by oTo )\n";ES;fi;;     6) S=M2;SC;if [[ $cur == "" ]];then R;exit 0;fi;;  esac;POS;done;
28777
Using the Nano text editor, I'm trying to save and exit a file.  I already have the file named.  I click Ctrl+X to exit. And then I click Y because I want to save the file. It asks for file to write, I pressed Enter to use the default name because its already named.  The problem is I get this message.   [Error writing /filename: Permission denied]   What am I doing wrong?
43776
I'm trying to go into an irb session with specific environment variables from a file with this command:  $ env $(cat env.sh) irb   But when I try press Tab after I type env. to complete it, I get this following error:  $ env $(cat env.-bash: unexpected EOF while looking for matching `)' -bash: syntax error: unexpected end of file   Another interesting thing is that if I'm logged in as root, this error does not occur.   Here's the output of find ~ -uid 0:  $ find ~ -uid 0 /home/(redacted)/.rpmdb /home/(redacted)/.rpmdb/Group /home/(redacted)/.rpmdb/Conflictname /home/(redacted)/.rpmdb/Installtid /home/(redacted)/.rpmdb/Sha1header /home/(redacted)/.rpmdb/Providename /home/(redacted)/.rpmdb/__db.002 /home/(redacted)/.rpmdb/Requirename /home/(redacted)/.rpmdb/Sigmd5 /home/(redacted)/.rpmdb/__db.001 /home/(redacted)/.rpmdb/Obsoletename /home/(redacted)/.rpmdb/.dbenv.lock /home/(redacted)/.rpmdb/Name /home/(redacted)/.rpmdb/Basenames /home/(redacted)/.rpmdb/Triggername /home/(redacted)/.rpmdb/Packages /home/(redacted)/.rpmdb/Dirnames /home/(redacted)/.rpmdb/__db.003   Can anyone explain to me why this is happening and if so, how do I fix it in when I'm not a root user?
51024
When I am running two while loop and trying to concatenating two variable strings (from two loops), the final output (string) is weird. I have tried different way to concatenating but did not get the answer: Below is the code: [I need vfile="var1_Amon_My_model1*.nc"]  #!/bin/bash jcount=1 extn="*.nc" while read line do mname=$line echo " Working on model - " $mname echo " and model number = "$jcount while read line do vname=$line vfile="${vname}""_Anom_""${mname}""${extn}" echo $vfile done&lt;varlists.txt echo "******************************************" jcount=$((jcount+1)) done&lt;model_test1.txt   In varlists.txt  var1 var2   In model_test1.txt  My_model1 My_model2   After executing the script, it is showing   Working on model -  My_model1  and model number = 1 *.ncm_My_model1 *.ncm_My_model1 ******************************************
16972
I'm working on a python script that passes file locations to an scp subprocess. That's all fine, but I'm in a situation where I may end up concatenating a path with a filename such that there's a double '/ in the path. I know that bash doesn't care if you have multiple file separators, but I'm wondering how exactly that is rectified. Is it bash that strips extra /s or does it really not matter ever?  I ask because it will save me several lines of code to check for extra /s while concatenating. I know it's not a big deal, but I'm curious as well. I have a bash script that has the line cd //usr (instead of cd /usr), which seems to imply there might be a significance to using multiple /s in a path
103099
While trying to  on ubuntu 16.04 I am trying to set up the stable repository and get the following:  $ sudo add-apt-repository \'deb [arch=amd64] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable' bash: syntax error near unexpected token `('   I am new to  Linux (today) so any advice would be much appreciated.
104430
What would be a more straight forward readable way of these commands?  And why exit 255 and not exit 1?  [ $# -eq 3 ] || { echo error ; exit 255 ; }  grep -q "string" &amp;&amp; exit 0
117381
Operating a standard bash shell on a server, the PS1 prompt defaults to ending in a $ for non-root users, and # for root.  IE:  ubuntu@server:~$ sudo su root@server:/home/ubuntu#   Why is this?
92978
I stumbled upon an example, which needed to be compiled with the additional option --shell-escape. Using this option it worked just fine, but I'm curious:     Why or when is this option needed and what does it actually do?
101254
it seems my bash-completion got corrupted. Every time I try to use command substitution, for example when I type  ls $(ls Deskto&lt;Tab&gt;   ..result is..  ls $(ls Desktobash unexpected eof while looking for matching ")".   I tried removing my .bashrc file and cp /etc/skel/bashrc ~/ to get a new one. That works until I add something into my new bashrc. Even when I do echo '#" &gt;&gt; ./.bashrc it breaks again. Removing my bash_aliases did not help either.  Also sudo apt-get install --reinstall bash-completion did not do the trick.  However there are some threads about similar problem, nothing works.  ANY hint will be greatly appreciated! :)
102550
I am writing a nightly build script in bash. Everything is fine and dandy except for one little snag:   #!/bin/bash  for file in "$PATH_TO_SOMEWHERE"; do       if [ -d $file ]       then               # do something directory-ish       else               if [ "$file" == "*.txt" ]       #  this is the snag               then                      # do something txt-ish               fi       fi done;   My problem is determining the file extension and then acting accordingly.  I know the issue is in the if-statement, testing for a txt file.    How can I determine if a file has a .txt suffix?
92427
I have an unexpected behaviour- following snippet fail with 'unbound variable' error:  #!/bin/bash set -u &lt;&lt;EOF a=a b=$a EOF   Tested on:  GNU bash, version 4.4.12(1)-release  GNU bash, version 4.2.46(2)-release
34727
I want to test if a directory doesn't contain any files. If so, I will skip some processing.  I tried the following:  if [ ./* == "./*" ]; then     echo "No new file"     exit 1 fi   That gives the following error:  line 1: [: too many arguments   Is there a solution/alternative?
19273
'     Number found where operator expected at ./scripttemp.perl line 5, near   ""sed -i -r "4" (Missing operator before 4?) String found where   operator expected at ./scripttemp.perl line 5, near "}" error.txt""   (Missing operator before " error.txt"?) syntax error at   ./scripttemp.perl line 5, near ""sed -i -r "4" syntax error at   ./scripttemp.perl line 5, near "s/[-.*-]//g}" Execution of   ./scripttemp.perl aborted due to compilation errors. '   I am getting this error running my script :  **#!/usr/bin/perl use warnings; use strict; exec("sed -i -r "4{s/\{\+//; s/\+}//; s/\[-.*-]//g}" error.txt");**   Please tell me what is wrong?
124117
There is a script which just adds extra lines to my /etc/hosts file to enable local development. Since it's pretty useful, I decided to keep it in a gist. When one of my friends downloaded the shell-script, changed the necessary permissions and tried to run it, it failed. The error shown is:  $ ./dev-mode : No such file or directory  Even though the script runs perfectly file on my computer. The /etc/hosts file exists in both our computers, the permissions and the owners are the same. Every thing is absolutely similar. Then he made a new file, copied the contents of the script to the new file, and changed the necessary permissions, and it RAN! To my eyes, there is no conceivable difference between the two files, but a diff does that they are difference, but doesn't highlight any line or any character... Nothing. The permissions are same, etc. Does ubuntu treat downloaded files somehow differently, and stop it from running? Absolutely same files, one runs and the other doesn't
60541
So I've been using 'sed' on linux for a while, but have had a bit of difficulty trying to use it on OSX since 'POSIX sed' and 'GNU sed' have so many little differences.  Currently I'm struggling with how to insert a line of text after a certain line number. (in this case, line 4)  On linux I would do something like this:  sed --in-place "4 a\  mode '0755'" file.txt   So on OSX I tried this:  sed -i "" "4 a\ mode '0755'" file.txt   However this keeps giving me a 'extra characters after \ at the end of a command' error.  Any ideas what's wrong here?  Do I have a typo?  Or am I not understanding another difference between versions of sed?
123086
Just out of curiousity.. Why are the line endings different for Windows and Unix.  I was looking around for the answer but not found.