Bash Script For Reading User Input then Compressing That Input to Tar file
I have this so far:
#!/bin/bashin the terminal, i drag the files into the terminal at the "Drag files..." dialog the problem i'm having is that when this runs, it compresses with the file(s) buried in the path. How to I change it to only compress the files and not the path? The strip option doesn't work. Thanks |
encryption
i already the encryption section set up.
|
'Read raw' is not going to work. The -r switch to the read builtin means 'raw', which disables backslash escapes and line continuation in the command line. If you want to use 'read', see this: http://wiki.bash-hackers.org/commands/builtin/read
|
Quote:
|
Including the absolute path would be the function of the desktop. If you remove the path then your script would fail if the files were not located in the same directory as your script.
Striping the path in tar is not so easy. One convoluted method would be to strip the path from the file in a loop, use the tar -C option and append the file to your archive then compress. Untested psuedo code would be something like. Code:
For x in $files |
Thanks, ill give that a try.
Quote:
|
Here is one quick method to strip path and filename but it will fail if they contain spaces. It also strips single quotes.
Code:
temp="${x%\'}" |
couldn't the script cd to the folder in question, then tar the file?
you'd have to separate the input into path and filename. also for troubleshooting i recommend prepending th elast command with 'echo' to see what would have been tar'd. |
cd doesn't work in a script.
|
^ what?
that would mean a significant number of my scripts wouldn't work. no really, it does work on my setup: GNU bash, version 4.4.12 |
Cd works only in the script shell. Or, maybe I'm just imagining that.
|
Don't all scripts create an instance of a shell?
|
try
Code:
file_name=`basename $file_and_path` |
Much easier then my suggestion. Although a better method would be to use
Code:
file_name=$(basename "$files") |
All times are GMT -5. The time now is 12:52 PM. |