Bashrc function errors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bashrc function errors
# 1  
Old 03-31-2017
Bashrc function errors

So I am messing around customizing my bashrc and I created a function that will move the apt proxy file depending on what parameter I pass.

It checks for two conditions either home or work (user provided) and moves the file according to where the file is currently located and what parameter it is given.

Function:
Code:
function aptproxy()
{
  echo $1
  if [ "$1" == 'work' -a -f /etc/apt/apt.conf.d/80proxy ]; then
      echo 'You are at work'
  elif [ $1 == 'work' -a !-f /etc/apt/apt.conf.d/80proxy ]; then
      echo 'You are set to home, switching to work'
      mv "/etc/apt/conf.d_tmp/80proxy" "/etc/apt/apt.conf.d/80proxy"
  elif [ $1 == 'home' -a -f /etc/apt/apt.conf.d/80proxy ]; then
      echo "You are setup for work, moving proxy"
      mv "/etc/apt/apt.conf.d/80proxy" "/etc/apt/conf.d_tmp/80proxy"
  elif [ $1 == 'home' a- !-f /etc/apt/apt.conf.d/80proxy ]; then
    echo "You are already configured for home"
  fi
}

output when calling it with one of the parameters (home or work) with set -xv

Code:
root@xubuntu:/home/user# aptproxy work
aptproxy work
+ aptproxy work
+ echo work
work
+ '[' work == work -a -f /etc/apt/apt.conf.d/80proxy ']'
+ '[' work == work -a '!-f' /etc/apt/apt.conf.d/80proxy ']'
bash: [: too many arguments
+ '[' work == home -a -f /etc/apt/apt.conf.d/80proxy ']'
+ '[' work == home -a '!-f' /etc/apt/apt.conf.d/80proxy ']'
bash: [: too many arguments

From this it looks like it is the mv commands causing the issue. I have tried them with the directories in quotes and without quotes and it yields the same results. From everything I've been reading that too many arguments error usually means a string variable is being split up into multiple pieces but with that output I don't see that happening?

Any help would be appreciated.

TIA


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-31-2017 at 02:40 PM.. Reason: Added CODE tags.
# 2  
Old 03-31-2017
Without digging deeper: I think the ! needs spaces around it.
# 3  
Old 03-31-2017
Quote:
Originally Posted by RudiC
Without digging deeper: I think the ! needs spaces around it.
annnnd I feel dumb. Ty for the quick response that worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to get $1 parameter in ~/.bashrc

Hi, i am trying to convert windows path to linux and do some action on equivalent mounted one for the same in linux. echo '\\server1\source\path\needed_files' | sed -e 's!\\!/!g' | sed -e 's!^//!/!' | sed -e 's!\(/server1/source/path\)\(.*\)!/home/$USER/mount/server1\2!'output: ... (5 Replies)
Discussion started by: greet_sed
5 Replies

2. Shell Programming and Scripting

bashrc not saving changes

I am trying to do some changes at bashrc file located at /etc directory of my server. First I tried to edit bashrc via FTP downloaded on my pc changed it and loaded back, but it seems like changes are not reflecting. Therefore I tried to change it via putty shel using vim bashrc command. but... (4 Replies)
Discussion started by: ninadgac
4 Replies

3. Shell Programming and Scripting

.bashrc file

Hi experts, I am using bash shell and I cant find any .bashrc file in my home dir. Can anybody please help me out here.... If .bashrc file is not there, from where my shell config operates? Also I want to set my prompt like... $ Please advice. (5 Replies)
Discussion started by: gentleDean
5 Replies

4. Shell Programming and Scripting

bashrc

i have made a few changes to my bashrc file...have set a few environmental variable that my shell scripts use. Is there any way that these changes can reflect in evryone else's bashrc who are in the network or do all of them have to copy those changes to their own bashrc file. (2 Replies)
Discussion started by: lassimanji
2 Replies

5. Shell Programming and Scripting

how do i look for my .bashrc file

hi i am using cygwin and would like to modify my .bashrc file. How can search to find where it is? I have looked at multiple bashrc file in /etc but none of them seemed to work..thanks (12 Replies)
Discussion started by: npatwardhan
12 Replies

6. Ubuntu

/etc/bashrc umask

Hi, I got this redhat ent 4 assigned to me now. /etc/bashrc if ; then umask 022 else umask 077 fi What does it mean? I created already three user and it never had 022 umask, always 077. Thank you in advance. (3 Replies)
Discussion started by: itik
3 Replies

7. UNIX for Dummies Questions & Answers

Major OS errors/Bash errors help!!!!

Hi all, dummy here.... I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: [: =: unary... (12 Replies)
Discussion started by: wcmmlynn
12 Replies

8. AIX

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (2 Replies)
Discussion started by: mcastill66
2 Replies

9. UNIX for Advanced & Expert Users

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (0 Replies)
Discussion started by: mcastill66
0 Replies

10. Shell Programming and Scripting

from bashrc to sh..??

:) as soon as i installed my software a couple of weeks ago.. (fedora core 2 vs, 2.6.8-1.521) i decided to switch the shell to sh shell and i know that .bashrc is the bash profile file(???) i want to use the sh version of the same file and make it the main profile file.. how can I switch it and... (3 Replies)
Discussion started by: moxxx68
3 Replies
Login or Register to Ask a Question