Bash variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash variables
# 1  
Old 03-19-2008
Bash variables

Ummm can anybody help me with this one?

Its prob quite simple.

I bascially have a file name say J1x2x3x7.dat

Im using the file name as a variable in a bash script. Want I want to do is extract most of the file name and make it a new variable expect with say one of the number now a wildcard, so have something like J1x*x3x7.dat as my new file name?

Can this be easily done. I'm sure it can smile.gif ?
# 2  
Old 03-19-2008
Yes, asterisks are permitted in filenames on most UNIX systems. However, using an asterisk in a filename is a really bad idea for lots of reasons and is generally avoided. Note that POSIX filenames cannot contain asterisks.
# 3  
Old 03-19-2008
Quote:
Originally Posted by RichieFondel
Ummm can anybody help me with this one?

Its prob quite simple.

I bascially have a file name say J1x2x3x7.dat

Im using the file name as a variable in a bash script. Want I want to do is extract most of the file name and make it a new variable expect with say one of the number now a wildcard, so have something like J1x*x3x7.dat as my new file name?

Can this be easily done. I'm sure it can smile.gif ?

Code:
file=J1x2x3x7.dat
newfile=J1x*x3x7.dat
mv "$file" "$newfile"

However, be aware that such a filename can cause problems.

See the POSIX standard for portable filenames:
General Concepts: Filenames
Definitions: Portable Filename Character Set

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Debian

Using sed with bash variables

Hi Guys I have another problem I'm trying to solve and hope that some one can help me here. This is the scenario: I have a file and I want to add a line on the 3rd line of the file using a bash script. but instead its adding the the bash variable $WEBSITE. Below is the bash script I'm... (6 Replies)
Discussion started by: linuxjunkie
6 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. Shell Programming and Scripting

Expect - bash and variables

I was wondering if anyone could provide some assistance. I trying to run an expect script within bash and get the results of a variable called RESULT. I Have tried a few things but none of them have worked. I know that the child process (the expect script) in this instance cannot set a variable... (6 Replies)
Discussion started by: ylafont
6 Replies

4. Shell Programming and Scripting

BASH arrays and variables of variables in C++

Sometimes it is handy to protect long scripts in C++. The following syntax works fine for simple commands: #define SHELLSCRIPT1 "\ #/bin/bash \n\ echo \"hello\" \n\ " int main () { cout <<system(SHELLSCRIPT1); return 0; } Unfortunately for there are problems for: 1d arrays:... (10 Replies)
Discussion started by: frad
10 Replies

5. Shell Programming and Scripting

Bash for loop with two variables

Hi, I have the following folder structure: TST500-1000 TST500-2000 TST500-3000 TST700-1000 TST700-2000 TST700-3000 TST900-1000 TST900-2000 TST900-3000 I would like to store the numbers in the first column (considering "-" as column separator) into a variable then the numbers in... (3 Replies)
Discussion started by: alex2005
3 Replies

6. Shell Programming and Scripting

Indirect variables in Bash

Hello, I've spent hours this morning reading various past forum posts and documentation pages but I can't find exactly what I need. I'm trying to call a variable with a variable in the name without having to make a third variable. For example: path=AB legAB=50 leg$path I want to... (8 Replies)
Discussion started by: DFr0st
8 Replies

7. Shell Programming and Scripting

Creating variables in bash

I am writing some scripts using bash and am wondering if there is a better way to perform the following set of formatting variables. s1=" " s2=" " s3=" " s4=" " s5=" " s6=" " s7=" " s8=" " frmt_titl="${bYl}%s${nClor}\n" frmt1_titl="${s1}$frmt_titl"... (10 Replies)
Discussion started by: kristinu
10 Replies

8. Shell Programming and Scripting

while loops and variables under bash

Hi, This is probably going to be very simple but i came across something i can't quite explain. Here is the situation: i have a list of files, which i'd like to process one by one (get the size, make some tests, whatever) and generate some statistics using different variables. Something... (5 Replies)
Discussion started by: m69w
5 Replies

9. Shell Programming and Scripting

how to use in bash variables and quotes

I have some troubles with variables and quotes... I want: if $URL is empty (no user input) go to http://www.localhost/index.php/ else add this string (search) "?s=+$URL" EXAMPLE: No user input string= http://www.localhost/index.php/ User input = "unix" string=... (3 Replies)
Discussion started by: aspire
3 Replies

10. UNIX for Dummies Questions & Answers

bash shell variables

Hi everyone, I have added this to my .bash_profile. Whenever I log in and when I type javac I get a error message (java: command not found). Does the order counts? PATH=$JAVA_HOME/bin:$PATH:$HOME/bin JAVA_HOME=$JAVA_HOME/usr/local/jdk1.3.1_02 export JAVA_HOME PATH Thanks ny (3 Replies)
Discussion started by: xNYx
3 Replies
Login or Register to Ask a Question