Importing a path/file into a bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Importing a path/file into a bash script
# 1  
Old 01-03-2011
Importing a path/file into a bash script

Hey, I'm new here. Basically, I'm trying to make a bash script that affects a file of my choice.

What I want to do is
Code:
$./script.sh /path/to/file.jpg

and then the bash script will know that variable=/path/to/file.jpg

Thanks!
# 2  
Old 01-03-2011
In your script.sh:
Code:
variable="$1"

Is it what you are looking for?
# 3  
Old 01-03-2011
No, what I'm looking for is a way to import text from the command line when I run the script.

Here is what I'm trying to do.

Code:
#! /bin/bash

echo 'Where is the file located?'
read location

COUNT=1

while [ $COUNT -lt 7 ]; do
    exif -t 0x000$COUNT --remove $location -o $location    
    let COUNT=COUNT+1
done

This little script strips out the exif GPS data (so if I upload a picture online, I don't have to worry about someone showing up at my house).

It loops from 0x0001 to 0x0006 and removes them. It then overwrites the file.

The issue is I don't want to have to type out the file names since I can't get autocomplete to work in BASH. So instead of setting the location of the file with:

Code:
echo 'Where is the file located?'
read location

I could just use ./script.sh ~/Desktop/file.jpg and script.sh will know that ~/Desktop/file.jpg shall be the location variable.
# 4  
Old 01-03-2011
Replace following two lines
Code:
echo 'Where is the file located?' 
read location

with
Code:
location="$1"

Now when you run script like below:
Code:
./script.sh /path/to/your/filename

1st argument ($1) will be set in location variable.
This User Gave Thanks to anurag.singh For This Post:
# 5  
Old 01-03-2011
Brilliant! Thank you. I didn't understand what you were saying in your first post. I'm still new to bash scripting, as you can see :P
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to trim folder and files within a path that share a common file extension

The bash will trim the folder to trim folder. Within each of the folders (there may be more than 1) and the format is always the same, are several .bam and matching .bam.bai files (file structure) and the bashunder that executes and trims the .bam as expected but repeats the.bam.bai extentions... (9 Replies)
Discussion started by: cmccabe
9 Replies

2. UNIX for Beginners Questions & Answers

Bash script - Remove the 3 top level of a full path filename

Hello. Source file are in : /a/b/c/d/e/f/g/some_file Destination is : /d/e where sub-directories "f" and "g" may missing or not. After copying I want /a/b/c/d/e/f/g/file1 in /d/e/f/g/file1 On source /a is top-level directory On destination /d is top-level directory I would like... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

Moving files from parent path to multiple child path using bash in efficient way

Hi All, Can you please provide some pointers to move files from Base path to multiple paths in efficient way.Folder Structure is already created. /Path/AdminUser/User1/1111/Reports/aaa.txt to /Path/User1/1111/Reports/aaa.txt /Path/AdminUser/User1/2222/Reports/bbb.txt to... (6 Replies)
Discussion started by: karthikgv417
6 Replies

4. Shell Programming and Scripting

Bash script not parsing file with spaces in path

Hi everyone, I'm trying to write my first ever shell script, the OS is Raspbian. The code I have written must be executed whenever a certain database has been modified. The database resides on a Windows server to which I have a mount point, and I have no control over the Windows server at all so... (2 Replies)
Discussion started by: gjws
2 Replies

5. Shell Programming and Scripting

Importing File fields into a script

Hi All, Kindly tell me how to import a file fields in a scripts scripts=adder.sh >> add values vi adder.sh (for example) N1=$1 N2=$2 N=$N1+$N2 *********** file.txt 2|1 3|4 5|6 (3 Replies)
Discussion started by: teefa
3 Replies

6. Shell Programming and Scripting

Reading XML in bash and importing in Mysql

Hi, I'm not a pro bashscript writer but I'm learning and want to learn about my mistakes. In the next script I have an error on rule 6 but I can't find what I'm doing wrong ... I daily receive a file xml.xml and have to import it in an mysql database in a few existing tables. #!/bin/bash... (2 Replies)
Discussion started by: garf0r
2 Replies

7. UNIX for Dummies Questions & Answers

Getting path name using bash script

I have this code to extract the directory name ($0:h) in tcsh. I am converting the code to bash and need a way to get the equivalent setting for DefRaytracPath set DefRaytracPath = `echo $0:h | awk 'BEGIN {FS="/tcsh"} {print $1"/prog"}'` (3 Replies)
Discussion started by: kristinu
3 Replies

8. Shell Programming and Scripting

Importing env from csh to bash

Hi All, In my account with csh shell, there are lots of env variables set and I want to import those all to bash in one stroke, is there any way to do it ? Thanks, D (1 Reply)
Discussion started by: Deei
1 Replies

9. Shell Programming and Scripting

importing functions from an external bash script

Hi all, I'm trying to import some functions I have saved in a file named functions.sh into a different script (protocol.sh). Can anybody show me how to do this? I tried source functions.sh as I would do at the terminal but source command cannot be found from within the script protocol.sh. ... (2 Replies)
Discussion started by: tevang
2 Replies

10. Shell Programming and Scripting

Bash Script to display directories in Path?

Hello there, As a newbie: The directories in PATH can be hard to distinguish when printed out as one line with colon .Please, can i have a sample script to display them,one to a line. Thank you. (1 Reply)
Discussion started by: debut
1 Replies
Login or Register to Ask a Question