how to get $1 parameter in ~/.bashrc


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to get $1 parameter in ~/.bashrc
# 1  
Old 08-23-2011
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.

Code:
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:
Code:
/home/$USER/mount/server1/needed_files

i can change directory to output. However , i couldnt make it to work when i use it in ~/.bashrc inside function.

Code:
win2linx () { 
echo '$1' | sed -e 's!\\!/!g' | sed -e 's!^//!/!' | sed -e 's!\(/server1/source/path\)\(.*\)!/home/$USER/mount/server1\2!'
}

i ran ,
Code:
$ win2linx \\server1\source\path\needed_files
$ $1

what has to be changed to get $1 value , i could not use "" it ignores \ in paths.

I appreciate your suggestions .
# 2  
Old 08-23-2011
Quote:
what has to be changed to get $1 value , i could not use "" it ignores \ in paths.
???
Code:
$ a='\\some\where \a\n\t'
$ echo "$a"
\\some\where \a\n\t

You should call your function so:
Code:
win2linx '\\server1\source\path\needed_files'

and use double quotes around $1.
# 3  
Old 08-23-2011
hi,
it works as expected.
Any other possibility to modify the code to call a function with just path ie,without single quotes?

would like to run :
Code:
win2linx \\server1\source\path\needed_files

# 4  
Old 08-23-2011
Code:
echo \\\\server1\\source\\path\\needed_files

But why? Smilie
# 5  
Old 08-23-2011
hi,
excuses, if i was not clear.

i get a path from windows machine so i do copy from windows and paste the path in linux terminal . i do not want to edit any except calling function.

so from terminal, i need to type like this which is easy !!!
Code:
 $ win2linx <path>

i don't want to inform the user to put single quotes beginning and end of the path ie call the function as
Code:
 $ win2linx '<path>'

# 6  
Old 08-23-2011
No way as a command argument. But you can add to your bash function something like this:
Code:
read -r -p'Enter a path: ' path
echo "$path"

This User Gave Thanks to yazu For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Fedora

.bashrc in Ubuntu 14.04

I am getting this: cmccabe@DTV-A5211QLM:~$ cat ~/.bashrc Command 'cat' is available in '/bin/cat' The command could not be located because '/bin' is not included in the PATH environment variable. cat: command not found cmccabe@DTV-A5211QLM:~$ nano .bashrc Command 'nano' is available in... (9 Replies)
Discussion started by: cmccabe
9 Replies

2. Shell Programming and Scripting

Call Script with Parameter (that has another parameter)

Hi. How do I achieve this sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies

3. Shell Programming and Scripting

Resolving a parameter which is passed as parameter

Hi, I have the following files. ->cat scr.sh export TMP_DIR=/home/user/folder1 export TMP_DIR_2=/home/user/folder2 while read line do cat "$line" done<file_list.dat ------------------------ -> cat file_list.dat $TMP_DIR/file1.txt $TMP_DIR_2/file2.txt --------------------------- -> cat... (6 Replies)
Discussion started by: barath
6 Replies

4. Shell Programming and Scripting

How to get the parameter value from the parameter file in perl?

hi all, i have a parameter file of following format, i want a method which can get the value of specific parameter. parameter file format: <Parameter Name="FileLocationWindows"> <Description> The directory location of the logger file. ... (1 Reply)
Discussion started by: laxmikant.hcl
1 Replies

5. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

6. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

7. UNIX for Advanced & Expert Users

unset .bashrc

Could someone please tell me how to unset your .bashrc? I have tried all of these. I can't find anything useful from google. unset -f .bashrc unset .bashrc (9 Replies)
Discussion started by: cokedude
9 Replies

8. 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

9. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 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