Getting text into command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting text into command line
# 8  
Old 05-03-2010
Code:
while read ip;do mount -t cifs //${ip}/share /mnt/share -o username =hiro;done < ipfile

# 9  
Old 05-04-2010
Yes the share mounts perfectly with that command with the ip address in it and the text file does contain the correct ip address but when i tried your code i got the errors listed in my last post. There is something just a little wrong with the syntax of that code or i have copied it out incorrectly. Can you see any mistakes anywhere either in the original code or in mine? The code i posted is cut and paste directly from my script so that is exactly as it is there.
Thanks for persevering, Hiro.

---------- Post updated at 06:23 PM ---------- Previous update was at 07:12 AM ----------

I've done a bit more playing and come up with this:

Code:
#ip=${awk '{print $1}' /home/hiro/Documents/ipaddress}
ip=$1192.168.1.2
echo $ip
sudo mount -t cifs //$ip/music /mnt/music -o username=hiro

As you can see i have commented out the line i thought was troublesome and told ip to have the ip address as it's value. For some reason, presumably the syntax i used it ignored the first character so i just banged another one in there and that gave me a print on the screen of the ip address i wanted. I had the last line commented out at that point as i didn't think it was the problem and as soon as i uncommented it the share mounted.
I think this proves that the first line is to blame? Can anyone shed any light?

Danmero, i am a little, make that a lot confused by your code, is that to replace both of the original lines or just the second one? I ran it on it's own and got an "Unexpected end of file error" but i think maybe it needs the first line to set the variable "$ip"? Is this right? If so it won't work now as the first lines seems to be at fault.
# 10  
Old 05-04-2010
hiro,
what are the results of following two commands:
Code:
cat /home/hiro/Documents/ipaddress

Code:
awk '{print $1}' /home/hiro/Documents/ipaddress

The output should be the same, namely the ip address from the ipaddress file.
In this case you can assign this ip address to a variable called ip like this:
Code:
ip=$(awk '{print $1}' /home/hiro/Documents/ipaddress)

If you want to assign the ip address to a variable called ip:
Code:
ip="192.168.1.2"

This is how I tested that:
Code:
$ cat ipaddress
192.168.1.2
$ awk '{print $1}' ipaddress
192.168.1.2
$ ip=$(awk '{print $1}' ipaddress)
$ echo $ip
192.168.1.2
$ ip="10.14.7.1"
$ echo $ip
10.14.7.1
$

HTH
# 11  
Old 05-04-2010
Success at last! Unfortunately i had made another silly mistake, remember how i had plain brackets when i first typed the code in and i then changed them to curly brackets? Well i changes both pairs but your latest post with the colour coding soon put me right and it now works a treat. All i need to do now is neaten the script up a bit and my first ever attempt at scripting will be a useful tool for me.
I couldn't have done it without your help so thank you very much for your patience, Hiro.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass each line of a text file as an argument to a command?

I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to a command. For example, it runs command --option "LINE 1", then command --option "LINE 2", etc. I am fetching object files from a library file, I have all the object file... (2 Replies)
Discussion started by: Paul Martins
2 Replies

2. Shell Programming and Scripting

How to accept command line argument as character or text if number is entered?

Hello Does the unix korn shell provide a function to convert number entered in command line argument to text or Character so that in next step i will convert Chr to Hex (6 Replies)
Discussion started by: aadityapatel198
6 Replies

3. Shell Programming and Scripting

Run a command on each line of a text file

Say I have a text file, with several lines. Each line may contain spaces or the # symbol. For each line, I want to pass that line as the path of a file, in order to add it to a tar file. I've tried this but doesn't work: cat contents.txt | xargs -0 `tar -uvf contents.tar $1`Any ideas? ... (3 Replies)
Discussion started by: Tribe
3 Replies

4. Shell Programming and Scripting

Command line: add text wrapper around words

I am trying to build a sinkhole for BIND. I created a master zone file for malicious domains and created a separate conf file, but I am stuck. I have a list of known bd domains that is updated nightly. The file simply contains the list of domains, one on each line: Bad.com Bad2.com... (4 Replies)
Discussion started by: uuallan
4 Replies

5. Shell Programming and Scripting

Replacing text in Perl given by command line

Hi I need to write a Perl script that the file given as first argument of the command line that will find all occurrences of the string given as the third argument of the command line and replace with the string given as the fourth argument. Name newfound file is specified as the second... (3 Replies)
Discussion started by: nekoj
3 Replies

6. UNIX for Advanced & Expert Users

unix command : how to insert text at the cursor location via command line?

Hi, Well my title isn't very clear I think. So to understand my goal: I have a script "test1" #!/bin/bash xvkbd -text blabla with xbindkeys, I bind F5 key in order it runs my test1 script So when I press F5, test1 runs. I'm under Emacs/Vi and I press F5 in order to have "blabla" be... (0 Replies)
Discussion started by: xib.be
0 Replies

7. Shell Programming and Scripting

cut command issue from a line of text

Hi, I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut... (5 Replies)
Discussion started by: asutoshch
5 Replies

8. UNIX for Dummies Questions & Answers

ksh command line editing text being overwritten

hi. i'm using ksh with set -o vi. if i am far down in a directory and try to edit the command line (esc-k to retrieve previous command) the cursor is being positioned over to the left on top of the directory text making the text very difficult to read or work with. seems to be problem with long... (2 Replies)
Discussion started by: jeffa123
2 Replies

9. Shell Programming and Scripting

Using ARGV, acepting text from command line

I want to be able to call in my file and make it do it's magic by basically giving it: FileNAME.pl searchTerm fileToSearch It runs, and gives me the answers I want, however, it gives me an error: Can't open GAATTC: No such file or directory at .//restriction_map_better.pl line 15... (2 Replies)
Discussion started by: silkiechicken
2 Replies

10. UNIX for Dummies Questions & Answers

replace text in a file from the command line...

I am having to do a lot of searching thru files to replace words. Is there a command that i can run that will alow me to hunt thru a group of files and replace one word with another without having to open each file idividually? -thanks;) (1 Reply)
Discussion started by: dudboy
1 Replies
Login or Register to Ask a Question