linux shell loop through all inputs except last
Shell
## declare an array variable
declare -a arr=("element1" "element2" "element3")
## now loop through the above array
for i in "${arr[@]}"
do
echo "$i"
# or do whatever with individual element of the array
done
# You can access them using echo "${arr[0]}", "${arr[1]}" alsolist = [1, 3, 6, 9, 12]
for i in list:
print(i) var data = 'three-dxf-master/' +
'\nfoobar/fumm' +
'\nthree-dxf-master/.DS_Store' +
'\nthree-dxf-master/.gitignore' +
'\nthree-dxf-master/LICENSE' +
'\nthree-dxf-master/README.md' +
'\nthree-dxf-master/bower.json' +
'\nthree-dxf-master/bower_components/' +
'\nthree-dxf-master/bower_components/.DS_Store' +
'\nthree-dxf-master/bower_components/dxf-parser/';
function parseData(data) {
var records = data.split(/\n/);
var result = records.reduce(function(acc, record) {
var fields = record.match(/[^\/]+\/?/g) || [];
var currentDir = acc;
fields.forEach(function (field, idx) {
// If field is a directory...
if (/\/$/.test(field)) {
// If first one and not an existing directory, add it
if (idx == 0) {
if (!(field in currentDir)) {
currentDir[field] = [];
}
// Move into subdirectory
currentDir = currentDir[field];
// If not first, see if it's a subdirectory of currentDir
} else {
// Look for field as a subdirectory of currentDir
var subDir = currentDir.filter(function(element){
return typeof element == 'object' && element[field];
})[0];
// If didn't find subDir, add it and set as currentDir
if (!subDir) {
var t = Object.create(null);
t[field] = [];
currentDir.push(t);
currentDir = t[field];
// If found, set as currentDir
} else {
currentDir = subDir[field];
}
}
// Otherwise it's a file. Make sure currentDir is a directory and not the root
} else {
if (Array.isArray(currentDir)) {
currentDir.push(field);
// Otherwise, must be at root where files aren't allowed
} else {
throw new Error('Files not allowed in root: ' + field);
}
}
});
return acc;
}, Object.create(null));
return result;
}
//console.log(JSON.stringify(parseData(data)));
console.log(parseData(data));for i in "Hello":
print(i)for x in "${@:1:$# - 1}" ; do
echo do something with "$x"
done
Also in Shell:
- Title
- install curl ubuntu
- Category
- Shell
- Title
- git remove Untracked files
- Category
- Shell
- Title
- install expo
- Category
- Shell
- Title
- ubuntu du sort by dir size
- Category
- Shell
- Title
- pod install react native failed
- Category
- Shell
- Title
- how to check error logs in linux
- Category
- Shell
- Title
- how to install mysql python
- Category
- Shell
- Title
- remove git from project
- Category
- Shell
- Title
- minikube without sudo
- Category
- Shell
- Title
- list all the files in a directory without the directory in linux
- Category
- Shell
- Title
- powershell set environment variable
- Category
- Shell
- Title
- react native install
- Category
- Shell
- Title
- install windows service
- Category
- Shell
- Title
- install google chrome linux
- Category
- Shell
- Title
- git view stash
- Category
- Shell
- Title
- windows subsystem for linux optional component is not enabled. please enable it and try again
- Category
- Shell
- Title
- how to stop a port in macos
- Category
- Shell
- Title
- statsmodels logit function
- Category
- Shell
- Title
- ubuntu bluetooth not listed
- Category
- Shell
- Title
- npm install react
- Category
- Shell
- Title
- make docker sudo less
- Category
- Shell
- Title
- install tmux ubuntu
- Category
- Shell
- Title
- instalación de angular cli
- Category
- Shell
- Title
- recursive grep recursion depth
- Category
- Shell
- Title
- how to avoid some files changes to not come in git status
- Category
- Shell
- Title
- delete local branch git
- Category
- Shell
- Title
- git find merge conflicts
- Category
- Shell
- Title
- Tensorflow GPU Installation conda
- Category
- Shell
- Title
- linux command to check memory usage in percentage
- Category
- Shell
- Title
- get full path of files in directory linux command
- Category
- Shell
- Title
- how to start nginx in linux
- Category
- Shell
- Title
- git delete repository command line
- Category
- Shell
- Title
- grep docker logs
- Category
- Shell
- Title
- powershell sharepoint copy file to other site collection
- Category
- Shell
- Title
- how to zip with tar command
- Category
- Shell
- Title
- pytesseract
- Category
- Shell
- Title
- install visual studio code raspberry pi
- Category
- Shell
- Title
- ubuntu install composer
- Category
- Shell
- Title
- git add tag
- Category
- Shell
- Title
- git init repo
- Category
- Shell
- Title
- vagrant 16
- Category
- Shell
- Title
- insall git onec2
- Category
- Shell
- Title
- centos 7 install iptables
- Category
- Shell
- Title
- git show stashes
- Category
- Shell
- Title
- install babel language
- Category
- Shell
- Title
- update fork repository
- Category
- Shell
- Title
- compare local git branch with remote
- Category
- Shell
- Title
- gats gatsby-plugin-offline
- Category
- Shell
- Title
- Endpoint Security VPN build 986000724 is already installed on this computer.
- Category
- Shell
- Title
- intel pinning threads
- Category
- Shell
- Title
- how to add font icon in gatsby
- Category
- Shell
- Title
- get-adcomputer servers only
- Category
- Shell
- Title
- single line comment in shell script
- Category
- Shell
- Title
- how to rename a file in ubuntu using terminal
- Category
- Shell
- Title
- install makecert windows 10
- Category
- Shell
- Title
- checking if a substring exists in a string bash
- Category
- Shell
- Title
- git command autocomplete
- Category
- Shell
- Title
- git undo pushed commit
- Category
- Shell
- Title
- push code to github command line
- Category
- Shell
- Title
- conda install keras
- Category
- Shell
- Title
- change user linuxcommand ch
- Category
- Shell
- Title
- pip3 not found
- Category
- Shell
- Title
- how to install axios in react
- Category
- Shell
- Title
- git clone with folder name
- Category
- Shell
- Title
- grub file path
- Category
- Shell
- Title
- install vuex
- Category
- Shell
- Title
- git get local branches
- Category
- Shell
- Title
- run mysql xampp shell
- Category
- Shell
- Title
- github undo last pushed commit
- Category
- Shell
- Title
- heic open linux
- Category
- Shell
- Title
- list used ports on mac
- Category
- Shell
- Title
- linux make executable
- Category
- Shell
- Title
- ubuntu remove temp files
- Category
- Shell
- Title
- rsync examples
- Category
- Shell
- Title
- upgrade yarn version
- Category
- Shell
- Title
- how to add images to git readme
- Category
- Shell
- Title
- linux min 19.10 install virtualbox
- Category
- Shell
- Title
- git how to add remote
- Category
- Shell
- Title
- pod install ruby: bad interpreter: No such file or directory
- Category
- Shell
- Title
- git delete local commit
- Category
- Shell
- Title
- ubuntu ec2 node mongodb connect ECONNREFUSED 127.0.0.1:27017
- Category
- Shell
- Title
- no ip raspberry manually update
- Category
- Shell
- Title
- bash copy
- Category
- Shell
- Title
- bash edit prompt display appearance
- Category
- Shell
- Title
- linux permission
- Category
- Shell
- Title
- revert to commit git
- Category
- Shell
- Title
- how to import microsoft.online sharepoint powershell
- Category
- Shell
- Title
- how to install specific package version npm
- Category
- Shell
- Title
- ffmpeg change audio codec from m4a to mp3
- Category
- Shell
- Title
- run specific script with an other user linux
- Category
- Shell
- Title
- install mongodb 2018 instructions
- Category
- Shell
- Title
- git rebase one commit
- Category
- Shell
- Title
- install laravel on windows
- Category
- Shell
- Title
- how to commit a branch in git
- Category
- Shell
- Title
- git undo add
- Category
- Shell
- Title
- Linux Mint reset xfce-panel
- Category
- Shell
- Title
- files not showing in ubuntu
- Category
- Shell
- Title
- react native blank screen linux
- Category
- Shell
- Title
- force git to use ssh
- Category
- Shell
- Title
- run msi on linux
- Category
- Shell