You are not logged in.

#1 2014-10-02 03:52:40

sant527
Member
Registered: 2009-06-21
Posts: 273

bash: script not working even after using shopt

below is script i am trying. I am trying to get the latest modified file in a folder:

#!/bin/bash
shopt -s extglob
name=$(echo *(om[1]))
echo $name

i am expecting filename instead *(om[1]) is echoed. As such the script does not give any error due to using shopt.

i try the command on commandline it gives the filename as output.

% cd other
% echo *(om[1])
mumbai123.txt

why echo *(om[1]) is working on commandline but not in bash script.

Last edited by sant527 (2014-10-02 03:53:53)

Offline

#2 2014-10-02 04:03:38

sant527
Member
Registered: 2009-06-21
Posts: 273

Re: bash: script not working even after using shopt

i changed the #!/bin/bash to #!/bin/zsh and also removed the shopt command. it works.

Offline

#3 2014-10-02 22:46:10

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: bash: script not working even after using shopt

sant527 wrote:

why echo *(om[1]) is working on commandline but not in bash script.

Are you using zsh as your shell?

Offline

#4 2014-10-03 12:25:30

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: bash: script not working even after using shopt

Assuredly, he is.

*(om[1]) in bash is a glob that matches the empty string, "om1", "om1om1", "om1om1om1", "om1om1om1om1", etc...

Offline

Board footer

Powered by FluxBB